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 || three = " " ++ show x
    | otherwise = ""
    where three = include3 x

include3 x
    | one3 = True
    | otherwise = if 0 < ten then include3 ten else False
    where
        one3 = x `mod` 10 == 3
        ten = x `div` 10