#include #define REP(i, n) for(int i=0; i<(n); i++) #define REP2(i, x, n) for(int i=x; i<(n); i++) using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); int w, n; cin >> w >> n; vector vc(n); REP(i, n){ cin >> vc[i]; } sort(vc.begin(), vc.end()); int count{0}, res{0}; REP(i, n){ res += vc[i]; if(res <= w){ count++; } } cout << count << endl; return 0; }