B = int(input()) N = int(input()) C = [0]*N sum = 0 cnt = 0 for i in range(N): C[i] = int(input()) sum += C[i] ave = int((sum+B)/N) C.sort() C.reverse() print(C) for i in range(N): j = 0 if C[i]>ave: for j in range(C[i]-ave): C[i] -= 1 cnt += 1 B += 1 elif C[i]0: for j in range(ave-C[i]): C[i] += 1 cnt += 1 B -= 1 print(cnt) #print(C)