#include #include #include #include #include #define rep(i, x) for(int (i) = 0; (i) < (x); (i) ++) #define MOD 1000000007 using namespace std; int main(){ int l, n; vector w; cin >> l >> n; rep(i, n){ int wi; cin >> wi; w.push_back(wi); } sort(w.begin(), w.end()); int count = 0, sum = 0; while(true){ if(count == n || sum + w[count] > l){ break; }else{ sum += w[count]; count ++; } } cout << count << endl; return 0; }