import qualified Data.ByteString.Char8 as C import Data.Char main :: IO () main = do ss <- C.getLine let (x,xs) = nextInt ss ss2 <- C.getLine let ans = solve 0 x ss2 print ans solve :: Int -> Int -> C.ByteString -> Int solve i n ss | i == n = 0 | otherwise = max d $ solve (i + 1) n xs where d = x - i - 1 (x,xs) = nextInt ss nextInt :: C.ByteString -> (Int, C.ByteString) nextInt ss | '0' <= x && x <= '9' = nextInt2 ss 0 | otherwise = nextInt $ C.tail ss where x = C.head ss nextInt2 :: C.ByteString -> Int -> (Int, C.ByteString) nextInt2 ss n | C.null ss = (n, ss) | '0' <= y && y <= '9' = nextInt2 ys (n * 10 + (digitToInt y)) | otherwise = (n, ys) where y = C.head ss ys = C.tail ss