def include3(n)
  if n % 10 == 3
    print " #{n}"
  end
  if n / 10 != 0
    include3(n / 10)
  end
end

n = STDIN.gets.chomp.to_i
(1..n).each do |i|
  if i % 3 == 0
    print " #{i}"
  else
    include3(i)
  end
end
print "\n"