num = gets.to_i
# puts num
(1..num).each {|i|
  catch(:break_loop) do
    if i % 3 == 0
      print " #{i}"
    elsif i % 10 == 3
      print " #{i}"
    else
      throw :break_loop
    end
  end
}
puts