#include using namespace std; int main(void){ int i = 0,v,l,n; cin >> l >> n; int w[n]; while(i < n) cin >> w[i++]; for(i = 0;i < n;){ 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; }