import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl (map read . words) <*> getl (map read . words) >>= print

solve :: [Int] -> [Int] -> Int
solve [k, t] cs = f 0 0 scs
  where
    scs = sort cs
    f n r [] = r
    f n r (x:xs) = if n+1 >= x then f (n+x) 0 xs else f (n+x) (x-n-1) xs

getl :: (String -> a) -> IO a
getl f = f <$> getLine
