import qualified Data.ByteString.Char8 as C import Data.Char import Data.Array.IO main :: IO () main = do s1 <- C.getLine let (l, r1) = nextInt s1 s2 <- C.getLine let (n, r2) = nextInt s2 xs <- newArray (0, 10100) 0 :: IO(IOUArray Int Int) s3 <- C.getLine set n s3 xs writeArray xs 10010 1000000 ans <- solve 0 l xs print ans set :: Int -> C.ByteString-> IOUArray Int Int -> IO () set n ss xs | n == 0 = return () | otherwise = set2 n ss xs set2 :: Int -> C.ByteString -> IOUArray Int Int -> IO () set2 n ss xs = do let (w,rs) = nextInt ss y <- readArray xs w writeArray xs w (y + 1) set (n - 1) rs xs solve :: Int -> Int -> IOUArray Int Int -> IO Int solve n l xs = do y <- readArray xs n if l >= y * n then do { t <- solve (n + 1) (l - y * n) xs; return $ t + y; } else return $ div l n nextInt :: C.ByteString -> (Int, C.ByteString) nextInt ss | isDigit x = nextInt2 0 ss | otherwise = nextInt $ C.tail ss where x = C.head ss nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString) nextInt2 n ss | C.null ss = (n, ss) | isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys | otherwise = (n, ys) where y = C.head ss ys = C.tail ss