B = int(input()) N = int(input()) C = sorted([int(input()) for _ in range(N)]) t = min(C[N//2], (sum(C) + B)//N) print(sum(abs(c - t) for c in C))