function Main(input) {
  let n = Number(input);
  for (let i = 1; i <= n; i++) {
    if (isValid(i)) {
      process.stdout.write(" " + String(i));
    }
  }
  console.log();
}

function isValid(x) {
  if (x % 3 === 0) {
    return true;
  }
  while (x !== 0) {
    if (x % 10 === 3) {
      return true;
    }
    x = parseInt(x / 10, 10);
  }
  return false;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
