from heapq import heapify, heappop, heappush



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

A = [-a for a in map(int, input().split())]



heapify(A)

while len(A) > 1:

    a, b = -heappop(A), -heappop(A)

    heappush(A, -(a - b))



print((max(0, -A[0] - 1)))
K, T = list(map(int, input().split()))

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

maxA = max(A)

ans = maxA - 1 - (K - maxA)

print((max(ans, 0)))
from heapq import heapify, heappop, heappush

K, T = list(map(int, input().split()))
A = [-a for a in map(int, input().split())]
heapify(A)
while len(A) > 1:
    a, b = -heappop(A), -heappop(A)
    heappush(A, -(a - b))
print((max(0, -A[0] - 1)))

K, T = list(map(int, input().split()))
A = list(map(int, input().split()))
maxA = max(A)
ans = maxA - 1 - (K - maxA)
print((max(ans, 0)))

-from heapq import heapify, heappop, heappush - -A = [-a for a in map(int, input().split())] -heapify(A) -while len(A) > 1: -    a, b = -heappop(A), -heappop(A) -    heappush(A, -(a - b)) -print((max(0, -A[0] - 1))) +A = list(map(int, input().split())) +maxA = max(A) +ans = maxA - 1 - (K - maxA) +print((max(ans, 0)))