def f(CB, m): s = 0 for c in CB: s += abs(m - c) return s B = int(input()) N = int(input()) if N == 1: print(0) else: CB = [int(input()) for _ in range(N)] l = min(CB) r = (sum(CB)+B) / N while r - l >= 1: lm = (2*l + r) / 3 rm = (l + 2*r) / 3 if f(CB, lm) > f(CB, rm): l = lm else: r = rm print(f(CB, int(r)))