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