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