#include using namespace std; int main(void){ int i,v,l,n; cin >> l >> n; int w[n]; for(i = 0;i < n;i++) cin >> w[i]; for(i = 0;;){ for(int t = i;t < n;++t){ if(w[i] > w[t]){ v = w[t]; w[t] = w[i]; w[i] = v; } } if(w[i] <= l) l -= w[i++]; else break; } cout << i << endl; }