#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; i++) int main() { cin.tie(nullptr); int L, N; cin >> L >> N; vector W(N); rep(i, 0, N) cin >> W[i]; sort(W.begin(), W.end()); int sum = 0; int cnt = 0; rep(i, 0, N) { if (sum + W[i] <= L) { sum += W[i]; cnt++; } else { break; } } cout << cnt << '\n'; }