'use strict';
const x = require('fs').readFileSync('/dev/stdin', 'utf8');
const num = Number(x);

for (let i = 3; i <= num; i++){
  if ((i%3===0)||(i%10===3)) {
    process.stdout.write(' ');
    process.stdout.write(''+i);
  } else if ((''+i).match(/3/)) {
    process.stdout.write(' ');
    process.stdout.write(''+i);
  }
}
console.log();

