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

for i in 1..gets.to_i
  if i % 3 == 0 or include3?(i)
    printf " #{i}"
  end
end
puts
