n = STDIN.gets
i=1
x=0

define_method(checkNum){
 x = i
 if(x%3 == 0){
   print " #{i}"
   endCheckNum
 }
 include3
}

define_method(include3){
 if(x%10 == 3){
   print " #{i}"
   endCheckNum
 }
 x/=10
 endCheckNum if x>0
 endCheckNum
}

define_method(checkNum){
 if((i+=1) <= n){
   checkNum
 }
}