let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const n = parseInt(content, 10);
  const nums = [];
  for (let i = 1; i <= n; i++) {
    let x = i;
    if (x % 3 == 0){
      nums.push(i);
      continue;
    }

    while(true) {
      if (x % 10 === 3){
        nums.push(i);
        break;
      }

      x = Math.floor(x / 10);
      if (x !== 0) {
        continue;
      } else {
        break;
      }
    }
  }

  console.log('', nums.join(' '))
});
