checkNum i = if i `mod` 3 == 0 then True
             else containsThree i
containsThree 0 = False
containsThree i = if i `mod` 10 == 3 then True
                  else containsThree $ i `div` 10
    

main = do
  ln <- getLine
  let n = read ln :: Int
  putStrLn (" " ++ (unwords . map show $ filter checkNum [1.. n]))