function Main(input) {
  input = Number(input);
  for(var i = 1; i <= input; i++){
      if(i % 3 === 0) process.stdout.write(' ' + i);
      else if(i.toString().indexOf('3') >= 0) process.stdout.write(' ' + i);
  }
  console.log();
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
