#include "bits/stdc++.h" using namespace std; vector C; int B, N; long long ans; long long calc(long long a){ long long nokori = B; long long temp = 0; for (int i = 0; i < N; i++) { temp += abs(a - C[i]); nokori += C[i] - a; } if (nokori < 0) return (long long) 1e18; ans = min(temp, ans); return temp; } int main() { cin >> B; cin >> N; C = vector(N); for (int i = 0; i < N; i++) { cin >> C[i]; } ans = (long long) 1e18; long long low = 0; long long high = (int)1e9 + 2; while (high - low > 10){ long long lowmid = (low + low + high) / 3; long long highmid = (low + high + high) / 3; cout << lowmid << " " << highmid << endl; if (calc(lowmid) <= calc(highmid)) high = highmid; else low = lowmid; } for (int i = max(0ll , low - 100); i < low + 100; i++) { calc(i); } cout << ans << endl; }