import Text.Printf

main = getLine >>= solve 1 . input

-- 入力
input :: String -> Int
input = read

include3 i x n
  | x `mod` 10 == 3 = do
    p i
    solve (i + 1) n
  | otherwise = do
    let x' = div x 10
    if x' > 0 then include3 i x' n
    else solve (i + 1) n

-- 解答
solve i n | i > n = putStrLn ""
  | otherwise= do
    if i `mod` 3 == 0 then do
      p i
      solve (i+1) n
    else do
      include3 i i n

p i = putStr $ printf " %d" i

