isth :: Int -> Bool
isth n | n == 0 = False
       | n `mod` 10 == 3 = True
       | otherwise = isth (n `div` 10)
solv :: Int -> Int -> String
solv i n | i > n          = "\n"
         | i `mod` 3 == 0 = " " ++ show i ++ solv (i+1) n
         | isth i         = " " ++ show i ++ solv (i+1) n
         | otherwise      = solv (i+1) n
solvM :: String -> String
solvM l = solv 1 (read l)
main = getLine >>= \l -> return (solvM l) >>= putStr