#include #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; int main() { int L,N; cin >> L >> N; vector W(N); REP(i,N) { cin >> W[i]; } sort(W.begin(),W.end()); int i = 0; while(1) { L -= W[i]; if(L<0) { i--; break; } i++; } cout << i << endl; return 0; }