n = STDIN.gets.to_i
i=1
x=0

define_method(:checkNum){
 x = i

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

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

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

checkNum