n, m = map(int, input().split()) C = list(map(int, input().split())) C.sort() cnt = 0 for i in range(n): while C[i] > 0 and m > 0: C[i] -= 1 m -= 1 if C[i] == 0: cnt += 1 print(cnt)