i = gets.chomp.to_i

a = []
1.step(i) do |i| 
  if i % 3 == 0
    a.push(i)
  else
    k = i 
    while k != 0
      if k % 10 == 3
        a.push(i)
        k = 0 
      else
        k /= 10
      end 
    end 
  end 
end

puts " "+a*" "