function Main(input) {
  const n = Number(input);
  let result = '';
  for (let i = 1; i <= n; i++) {
    if (i % 3 === 0){
      result += ' ' + i;
    }
    else if (String(i).indexOf('3') != -1) {
      result += ' ' + i;
    } else {
      
    }
  }
  console.log(result);
}

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