#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) long long calc(const vector &v, long long t) { long long ret = 0; for (long long x: v) ret += abs(x - t); return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; long long b; cin >> b >> n; vectorc(n); REP (i, n) cin >> c[i]; sort(c.begin(), c.end()); long long sum = 0; REP (i, n) sum += c[i]; long long ret = calc(c, (sum + b) / n); if (sum >= n * c[n/2]) ret = min(ret, calc(c, c[n/2])); cout << ret << endl; return 0; }