main = do
  ln <- getLine
  let n = read ln :: Int
  putStrLn . concat $
    [" " ++ show x | x <- [1..n], check x]
check :: Int -> Bool
check x
  | x `mod` 3 == 0 = True
  | check2 x = True
  | otherwise = False
check2 :: Int -> Bool
check2 x = do
  if x == 0
    then False
    else
      if x `mod` 10 == 3
        then True
        else check2 (x `div` 10)