B = input() N = input() C = [int(raw_input()) for _ in xrange(N)] avg = sum(C)/N+1 amari, tarinai = 0, float('inf') if all(C[0]==c for c in C): print 0 exit() while amari+B < tarinai: amari = sum(c-avg for c in C if c > avg) tarinai = sum(avg-c for c in C if c < avg) avg -= 1 print amari+tarinai