There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all.  There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.  Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before.  Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
k,t=map(int,input().split())
a=list(map(int,input().split()))

from collections import deque
d={}
numbers=deque([])
for i in range(t):
    d[i+1]=a[i]

d=sorted(d.items(),key=lambda x: x[1],reverse=True)

for j in d:
    numbers.extend([j[0]]*j[1])

seq=[]

for k in range(len(numbers)):
    if k%2==0:
        b=numbers.popleft()
    else:
        b=numbers.pop()
    seq.append(b)


from itertools import groupby

length=0
gr =groupby(seq)
for key, group in gr:
    length=max(length, len(list(group)))

print(length-1)
k,t=map(int,input().split())
a=list(map(int,input().split()))

ans=max(max(a)-1 - (k-max(a)),0)
print(ans)