main = solve

solve = do
    x <- readLn
    let str = createLine x
    putStrLn str

createLine :: Int -> String
createLine w = concat . (map step) $ [1..w]

step :: Int -> String
step x
    | x `mod` 3 == 0 || one == '3' = " " ++ show x
    | otherwise = ""
    where one = let numStr = show x
                in last numStr