#include "bits/stdc++.h" 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(W.begin(),W.end()); int cnt=0, w=0; for (int i = 0; i < N; i++) { if (w + W[i] <= L) { w += W[i]; cnt++; } else break; } cout << cnt << endl; }