answers = []
n = gets.chomp.to_i
for i in 1..n
  if i%3 == 0
    answers.push(i)
  elsif i%10 == 3
    answers.push(i)
  elsif i == 30 || i == 31 || i == 32 || i == 33 || i == 34 || i == 35 || i == 36 || i == 37 || i == 38 || i == 39
    answers.push(i)
  end
end
print " "
puts answers.join(' ')