#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; //#include int main() { long long int b, n; cin >> b >> n; vectorw; long long int s = b; for (int i = 0; i < n; i++) { long long int t; cin >> t; w.push_back(t); } sort(w.begin(), w.end()); long long int m = w[n % 2 == 0 ? n / 2 - 1 : n / 2]; long long int x = m; if (s >= m*n)x = s / n; long long int ans = 0; for (int i = 0; i < n; i++) { ans += abs(w[i] - x); } cout << ans << endl; return 0; }