import heapq n, m = map(int, input().split()) c = list(map(int, input().split())) heapq.heapify(c) emptied = 0 for _ in range(m): current = heapq.heappop(c) new_val = current - 1 if new_val > 0: heapq.heappush(c, new_val) else: emptied += 1 print(emptied)