module Main where
import Data.List
getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  k:t:_ <- getInts
  as <- getInts
  print $ solve k t as
  return ()

solve k t xs
  | t == 1    = head xs - 1
  | otherwise = if d < 0
                then 0
                else d - 1
  where
    m = maximum xs
    s = sum xs
    d = m - (s - m)
