n = gets.to_i
count = []
for i in 1..n do
 x = i
 if x % 3 == 0
 count.push(i)

 else
 while x>0 && x%10 != 3 do
 x /= 10
 end
 if x % 10 == 3
 count.push(i)
 end
 end
 end
 
 print(" ")
 puts count.join(" ")
 
