#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; // constexpr int mod = 1000000007; constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll B; int N; cin >> B >> N; vector C(N); for(int i = 0; i < N; ++i) cin >> C[i]; ll sum = accumulate(begin(C), end(C), 0LL); ll ans = sum; for(int i = 0; i < N; ++i){ ll plus = 0, minus = 0; for(int j = 0; j < N; ++j){ if(j == i) continue; if(C[j] > C[i]) plus += C[j] - C[i]; else minus += C[i] - C[j]; } if(plus + B >= minus) chmin(ans, plus + minus); } cout << ans << endl; return 0; }