solve :: Int -> Int -> [String]
solve i n
  | i > n = []
  | mod	i 3 == 0 || (elem '3' $ show i) =	" " : show i : solve (i+1) n
  | otherwise =	solve (i+1) n

main = readLn >>= putStrLn . concat . solve 1