n = gets.to_i
i = 0
while ((i += 1) <= n) do
  x = i
  while (x / 10 != 0) do
    x /= 10 if (x % 10 != 3)
    break if (x % 10 == 3)
  end
  print (i % 3 == 0) ? " #{i}" : ((x % 10 == 3) ? " #{i}" : "")
  puts "" if (i == n)
end