def include3?(x)
  if x % 10 == 3
    true
  elsif x != 0
    include3?(x / 10)
  else
    false
  end
end

n = gets.chomp.to_i

(1...n).each do |i|
  if i % 3 == 0 || include3?(i)
    print " #{i}"
  end
end
puts