n = gets.to_i
i = 1
while true
  x = i
  if x % 3 == 0
    print " ",i
  else
    loop do
      if x % 10 == 3
         print " ",i
         break
      end
      x /= 10
      break if x == 0
    end
  end
  i += 1
  break if (i > n)
end
print "\n"
