N, M = map(int, input().split()) C = list(map(int, input().split())) l = len(C) while(M != 0): M -= 1 min_c = 100000 min_c_loc = 10 for i in range(l): if (C[i] < min_c and C[i] != 0): min_c = C[i] min_c_loc = i C[min_c_loc] -= 1 empty_box = 0 for c in C: if (c == 0): empty_box += 1 print(empty_box)