var input=require("fs").readFileSync("/dev/stdin","utf8");
input=input.split("\n");
var oup="";

for(let i=3;i<=input[0];i++){
    if(i%3==0||String(i).indexOf('3')!=-1)oup+=" "+i
}

console.log(oup);
