havecandy = int(input()) boxnum = int(input()) candybox = [int(elem) for elem in input().split()] average = sum(candybox) // boxnum result = 0 for cnt in range(boxnum): result += abs(candybox[cnt] - average) print(result)