include3 :: Int -> Bool
include3 x
    | x == 0    = False
    | otherwise = if x `mod` 10 == 3 then True else include3 $ x `div` 10

solve :: Int -> String
solve n = " " ++ (unwords $ map show $ filter (\x -> x `mod` 3 == 0 || include3 x) [1 .. n])

main :: IO ()
main = readLn >>= putStrLn . solve