import numpy as np
k, t = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))
a.sort()
import heapq
heapq.heapify(a)
b = heapq.heappop(a)
b += 1
while len(a) > 0:
    c = heapq.heappop(a)
    if b < 0:
        heapq.heappush(a, b)
    b = c + 1
print(-b)

501ea3c3a046c0684823899ccaba630be4ec677a
<mask token>

<mask token>
a.sort()
<mask token>
heapq.heapify(a)
<mask token>
b += 1
while len(a) > 0:
    c = heapq.heappop(a)
    if b < 0:
        heapq.heappush(a, b)
    b = c + 1
print(-b)

<mask token>
k, t = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))
a.sort()
<mask token>
heapq.heapify(a)
b = heapq.heappop(a)
b += 1
while len(a) > 0:
    c = heapq.heappop(a)
    if b < 0:
        heapq.heappush(a, b)
    b = c + 1
print(-b)

import numpy as np
k, t = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))
a.sort()
import heapq
heapq.heapify(a)
b = heapq.heappop(a)
b += 1
while len(a) > 0:
    c = heapq.heappop(a)
    if b < 0:
        heapq.heappush(a, b)
    b = c + 1
print(-b)
