#include "bits/stdc++.h" using namespace std; using ll = long long; using ull = unsigned long long; using vb = vector; using vvb = vector; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using pii = pair; using pll = pair; #define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define eb(val) emplace_back(val) const double PI = acos(-1); const double EPS = 1e-10; const ll MOD = 1e9+7; //#define int ll void cioacc(){//accelerate cin/cout cin.tie(0); ios::sync_with_stdio(false); } signed main(){ int l,n; cin >> l >> n; vi a(n); REP(i,n) cin >> a.at(i); sort(ALL(a)); int wt = 0; int ans = 0; REP(i,n){ if(wt+a.at(i)>l) break; wt += a.at(i); ++ans; } cout << ans << endl; }