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