import Control.Monad
main = do
  n_in <- getLine
  let n = (read :: String -> Int) n_in
  call n 1 1
  
  where
    call :: Int -> Int -> Int -> IO ()
    call n i x = do
      if i`mod`3==0 then f1 i
      else if i`mod`10==3 then f1 i
      else f2 i x
      
      if i<n then call n (i+1) (i+1)
      else putStrLn ""
      
    f1 i = do
      --putStr " CHECK_NUM"
      putStr $ (" " ++ show i)
    f2 i x = 
      if i`div`10>0 && x`mod`10==3 then f1 i
      else if i`div`10>0 && x`div`10>0 then f2 i (x`div`10)
      else return ()
