N, M = list(map(int, input().split())) C = list(map(int, input().split())) for i in range(M): C.sort() for j in range(M): if C[j] <= 0 : continue else: C[j] -= 1 break print(C.count(0))