import Data.Char main = getContents >>= putStrLn . show' . all ok . words where show' p = if p then "OK" else "NG" ok s | (not.isDigit) (head s) = False | otherwise = let (n,xs) = head (reads s) in 0<=n && n<=12345 && null xs