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
  | x `mod` 10 == 3 = True
  | x `div` 10 /= 0 && (x `div` 10) `mod` 10 == 3 = True
  | otherwise = False