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 0 = return ()
f x = do
    f (x - 1)
    if (multipleOf3 x || contain3 x) 
        then putStr $ " " ++ show x 
        else return()

main = getLine >>= f . read
