#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,m,n) for(int i=m;i<n;i++)


int main(){
    int L, N;
    cin >> L >> N;
    vector<int> W(N);
    rep(i, N) cin >> W[i];
    sort(begin(W), end(W));

    int count = 0;
    for(;L > 0;){
        L -= W[count];
        count++;
    }
    cout << count-1 << endl;
    return 0;
}