#include #include #include using namespace std; int main () { int L; int N; cin >> L >> N; vector W(N); for (int i = 0 ; i < N; ++i) { cin >> W[i]; } sort(W.begin(), W.end()); int sum = 0; for (int i = 0; i < N; ++i) { sum += W[i]; if (sum > L) { if (sum - 1 < 0) { cout << 0 << endl; } else { cout << (sum - 1) << endl; } } } }