local ior = io.input() local b, n = ior:read("*n", "*n") local t = {} local sum = 0 for i = 1, n do local a = ior:read("*n") t[i], sum = a, sum + a end table.sort(t) local midpos = math.floor((n + 1) / 2) local dstval = t[midpos] if(sum + b < dstval * n) then dstval = math.floor((sum + b) / n) end local cnt = 0 for i = 1, n do cnt = cnt + math.abs(t[i] - dstval) end print(cnt)