import numpy as np def main(): b = int(input()) n = int(input()) c = np.array([int(input()) for _ in range(n)], dtype='int64') # bが小さいと中央値np.median(c)を実現できない。 # n * x = sum(c) + bをみたすxと中央値の小さい方を作る x = min(np.median(c), (np.sum(c) + b) // n) ans = sum([abs(i - x) for i in c]) print(ans) if __name__ == "__main__": main()