Mr. Takahashi wants to eat one cake per day from a collection of K cakes, each of a different type. He aims to minimize the number of consecutive days he eats the same type of cake. Given the number of cakes of each type, find the minimum number of days he eats the same type of cake as the previous day. Constraints: 1 ≤ K ≤ 10000, 1 ≤ T ≤ 100, 1 ≤ a_i ≤ 100, and a_1 + a_2 + ... + a_T = K. The input is given as K T followed by a list of a_i. Output the minimum number of consecutive days with the same type of cake. Example input and output are provided.

# Buggy version:
k, t = list(map(int, input().split()))
nums = list(map(int, input().split()))

m = max(nums)
rest = k - m
if max - rest - 1 > 0:
    print(max - rest - 1)
else:
    print(0)


# Fixed version:
k, t = list(map(int, input().split()))
nums = list(map(int, input().split()))

m = max(nums)
rest = k - m
if m - rest - 1 > 0:
    print(m - rest - 1)
else:
    print(0)

# Buggy version:
N,K = map(int,input().split())
A = list(map(int,input().split()))
print(max(2*max(A)-K-1,0))

# Fixed version:
K,T = map(int,input().split())
A = list(map(int,input().split()))
print(max(2*max(A)-K-1,0))

# Buggy version:
K, T = map(int, input().split())
a = list(map(int, input().split()))
if max(a) < (K+1)//2:
	print(max(a) - (K+1)//2)
else:
	print(0)


# Fixed version:
K,T = map(int,input().split())
A = list(map(int,input().split()))
a = max(A)
if a<=(K+1)//2:
    print(0)
else:
    print(2*a-K-1)

# Buggy version:
K, T = map(int, input().split())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)

print(max(0, A[0] - 1 - sum(A[1:]))

# Fixed version:

K, T = map(int, input().split())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)

print(max(0, A[0] - 1 - sum(A[1:])))

# Buggy version:
k,t = map(int,input().split())
a = list(map(int,input().split()))
if t == 1:
  print(k-1)
else:
  print(max(0,2*(max(a)-(k+1)//2)))

# Fixed version:
k, t = map(int, input().split())
a = list(map(int, input().split()))
num = max(a)
if (k + 1) // 2 >= num:
    print(0)
else:
    print(num * 2 - k - 1)

# Buggy version:
n,k=map(int,input().split())
a=list(map(int,input()split()))
s=max(a)
print(max(2*s-n-1))

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=max(a)
print(max(2*s-n-1,0))

# Buggy version:
K,T=map(int,input().split())
a=list(map(int,input().split()))

maxi=max(a)
other = sum(a)-maxi
print(maxi,other)

if maxi<=other:
    print(0)
else:
    print(maxi-other-1)

# Fixed version:
K,T=map(int,input().split())
a=list(map(int,input().split()))

maxi=max(a)
other = sum(a)-maxi
#print(maxi,other)

if maxi<=other:
    print(0)
else:
    print(maxi-other-1)

# Buggy version:
N = list(map(int, input().split()))
Q = list(map(int, input().split()))
maxQ = max(Q)
rest = N[0] - 1
print(max([maxQ-rest-1, 0]))

# Fixed version:
N = list(map(int, input().split()))
Q = list(map(int, input().split()))
maxQ = max(Q)
rest = N[0] - maxQ
print(max([maxQ-rest-1, 0]))

# Buggy version:
k,t = map(int,input().split())
A = list(map(int,input().split()))
print(max(2*max(A) - sum(A) -1))

# Fixed version:
k,t = map(int,input().split())
A = list(map(int,input().split()))
print(max(0,2*max(A) - sum(A) -1))

# Buggy version:
K,T = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=1)
if a[0] <= (K+1)//2:
    print(0)
else:
    if T == 1:
        print(a[0]-1)
    else:
        print(2*a[0] - K)


# Fixed version:
K,T = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=1)
if a[0] <= (K+1)//2:
    print(0)
else:
    print(2*a[0] - K-1)

# Buggy version:
K, T = map(int, input().split())
a = sorted(map(int, input().split()), reverse=True)

if T == 1:
    print(K-1)

print(max(a[0]-sum(a[1:])-1,0))


# Fixed version:
K,T = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
print(max(0,a[0] -sum(a[1:]) -1))

# Buggy version:
k,t=map(int,input().split())
a = list(map(int,input().split()))
sm = sum(a)
mx = max(a)
print(max(0,(mx-(sm+1)//2)*2))

# Fixed version:
k,t=map(int,input().split())
a = list(map(int,input().split()))
mx = max(a)
print(max(0,(mx-(k+1)//2)*2-1))

# Buggy version:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    if len(A)==1:
        ans = A[0]
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


# Fixed version:
def examA():
    S = SI()
    ans = "No"
    flag = False
    for s in S:
        if flag:
            if s=="F":
                ans = "Yes"
                break
        else:
            if s=="C":
                flag = True
    print(ans)
    return

def examB():
    K, T = LI()
    A = LI(); A.sort()
    ans = max(0,A[-1]*2-sum(A)-1)
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

# Buggy version:
K,T=map(int,input().split())
a=list(map(int,input().split()))
print(max(a)-(K-max(a))-1,0)

# Fixed version:
K,T = map(int,input().split())
a = list(map(int,input().split()))
ma = max(a)
print(max(ma-1-(K-ma),0))

# Buggy version:
K, T = map(int, input().split())
A = list(map(int, input().split()))

print(max(A) - (K-max(A)+1))

# Fixed version:
K, T = map(int, input().split())
A = list(map(int, input().split()))

print(max(0, max(A) - (K-max(A)+1)))

# Buggy version:
k,t = map(int,input().split())
a= list(map(int,input().split()))
sa = sum(a)
ma = max(a)

print(max(sa-ma-1,0))

# Fixed version:
k,t = map(int,input().split())
a= list(map(int,input().split()))
sa = sum(a)
ma = max(a)

print(max(ma-(sa-ma)-1,0))

# Buggy version:
K,T,*A=map(int,open(0).read().split());print(max(0,(max(A)+-K//2)*2-K%2^1))

# Fixed version:
K,T,*A=map(int,open(0).read().split());print(max(0,(max(A)+-K//2)*2-(K+1)%2))

# Buggy version:
K,T = map(int,input().split())
a = list(map(int,input().split()))

a = sorted(a,reverse = True)
ans = a.pop(0) - sum(a) - 1
if a >= 0:
    print(ans)
else:
    print(0)

# Fixed version:
K,T = map(int,input().split())
a = list(map(int,input().split()))

a = sorted(a,reverse = True)
ans = a.pop(0) - sum(a) - 1
if ans >= 0:
    print(ans)
else:
    print(0)

# Buggy version:
K, T = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A, reverse=True)
print(A[0] - sum(A[1:]) - 1)

# Fixed version:
K, T = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A, reverse=True)
print(max(A[0] - sum(A[1:]) - 1, 0))

# Buggy version:
k,t,*a=map(int,open(0).read().split());print(max(max(a)*2-sum(a),1)+1)

# Fixed version:
k,t,*a=map(int,open(0).read().split());print(max(max(a)*2-sum(a),1)-1)

# Buggy version:
n,m=map(int,input().split())
arr=list(map(int,input().split()))
maximum=max(arr)
if (maximum-1)<=(sum(arr)-maximum):
  print(0)
else:
  print(sum(arr)-maximum)

# Fixed version:
n,m=map(int,input().split())
arr=list(map(int,input().split()))
maximum=max(arr)
if (maximum-1)<=(sum(arr)-maximum):
  print(0)
else:
  print((maximum-1)-(sum(arr)-maximum))

# Buggy version:
K, T = map(int, input().split())
a = list(map(int, input().split()))
print(max(a)-(sum(a)-max(a))-1, 0)

# Fixed version:
K, T = map(int, input().split())
a = list(map(int, input().split()))

print(max(0, 2*max(a)-sum(a)-1))

# Buggy version:
k,t=map(int,input().split())
a=list(map(int,input().split()))
m=max(a)
n=k-m
print(min(m-n-1,0))

# Fixed version:
k,t=map(int,input().split())
a=list(map(int,input().split()))
m=max(a)
print(max(0,m-1-(k-m)))

# Buggy version:
k,t = map(int, input().split())
list_cake = list((map(int, input().split())))
list_cake.sort()
if len(list_cake) == 1:
    print(k-1)
elif list_cake[-1] <= k/2:
    print(0)
else:
    print(k - (k-list_cake[-1]) * 2)


# Fixed version:
k,t = map(int, input().split())
list_cake = list((map(int, input().split())))
list_cake.sort()
if list_cake[-1] <= k/2:
    print(0)
else:
    print(k - (k-list_cake[-1]) * 2 - 1)

# Buggy version:
K,T=map(int,input().split())
A=list(map(int,input().split()))
M=max(A)
print(max(A-1-(K-A),0))

# Fixed version:
K, T = map(int, input().split())
A = list(map(int, input().split()))
print(max(0, (max(A)-1) - (K-max(A))))

# Buggy version:
def inpl(): return list(map(int, input().split()))
K, T = inpl()
a = inpl()
print(max(max(a)*2-n-1, 0))

# Fixed version:
def inpl(): return list(map(int, input().split()))
K, T = inpl()
a = inpl()
print(max(max(a)*2-K-1, 0))

# Buggy version:
l=list(map(int, input().split()))
r=list(map(int, input().split()))
print(2*max(r)-l[0]-1)

# Fixed version:
l=list(map(int, input().split()))
r=list(map(int, input().split()))
print(max(0,2*max(r)-l[0]-1))

# Buggy version:
K, T = list(map(int, input().split()))
a = list(map(int, input().split()))

# def remax(seq):
#     m = max(seq)
#     for idx,i in enumerate(seq):
#         if m==i:
#             return (idx, m)
#
# lastK = -1
# cnt = 0
# for _k in range(K):
#     remax
#

print(max(a)*2-sum(a)-1)


# Fixed version:
K, T = list(map(int, input().split()))
a = list(map(int, input().split()))

# def remax(seq):
#     m = max(seq)
#     for idx,i in enumerate(seq):
#         if m==i:
#             return (idx, m)
#
# lastK = -1
# cnt = 0
# for _k in range(K):
#     remax
#

print(max(0,max(a)*2-sum(a)-1))