multipleOf3 x = (mod x 3) == 0
contain3 0 = False
contain3 x =
    if (mod x 10) == 3 
        then True
        else contain3 $ div x 10

f ::Int -> IO()
f x = putStrLn $ " " ++  (unwords .  map show $ [ a | a <- [1..x] , multipleOf3 a || contain3 a])

main = getLine >>= f . read . getLine
