solv :: Int -> Int -> String
solv i n | i <= n = if i `mod` 3 == 0 || i `mod` 10 == 3
                    then " " ++ show i ++ solv (i+1) n
                    else solv (i+1) n
         | otherwise = "\n"
solvM :: String -> String
solvM l = solv 1 (read l)
main = getLine >>= \l -> return (solvM l) >>= putStr