main = do
    n <- getLine 
    putStrLn $ concat (map (disp) (calc 1 (read n)))

disp :: Int -> String
disp x = " " ++ (show x)

calc :: Int -> Int -> [Int]
calc x n
    | x > n = []
    | x `mod` 3 == 0 = x : (calc (x+1) n)
    | x `mod` 10 == 3 = x : (calc (x+1) n)
    | (x `div` 10) `mod` 10 == 3 = x : (calc (x+1) n)
    | (x `div` 100) `mod` 10 == 3 = x : (calc (x+1) n)
    | (x `div` 1000) `mod` 10 == 3 = x : (calc (x+1) n)
    | otherwise = calc (x+1) n


