B = int(input()) N = int(input()) A = [] move = 0 for i in range(N): A.append(int(input())) X = (sum(A)+B)//N for i in range(N): if A[i] != X: move += abs(A[i]-X) print(move)