import Data.List

main :: IO ()
main = do
  [k, t] <- getInts
  ns <- zip [1..] <$> getInts
  print $ solve k t ns

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> Int -> [(Int, Int)] -> Int
solve k t ns = max (mx - 1 - (k - mx)) 0
  where
    (ma, mx) = maximumBy (\(_, a) (_, b) -> compare a b) ns
