N, M = list(map(int, input().split())) C = list(map(int, input().split())) zero_count = 0 for i in range(M): C.sort() if C[0] == 0: zero_count += 1 C.pop(0) else: C[0] -= 1 print(zero_count)