import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [k,t] <- getIntList
    as <- getIntList
    let ans | m <= l = 0
            | even k = (m-l-1)*2 + 1
            | odd k = (m-l)*2
            where l = (k+1) `div` 2
                  m = maximum as
    print ans