process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const n = Number(lines[0]);
  let out = "";
  for (let i = 1; i <= n; i++) {
    let x = i;
    if (x % 3 === 0) {
      out += ` ${i}`;
    } else {
      while (x) {
        if (x % 10 === 3) {
          out += ` ${i}`;
          break;
        }
        x = Math.floor(x / 10);
      }
    }
  }
  console.log(out);
});

