#include #define rep(i,a,b) for(int i = (a); i < (b); i++) #define all(A) (A).begin(),(A).end() #define MOD 1000000007 using namespace std; using ll = long long; using Graph = vector>; int main() { int l,n; cin >> l >> n; vector W(n); rep(i,0,n) cin >> W[i]; sort(all(W)); int ans = 0; rep(i,0,n){ if(l > 0){ l -= W[i]; ans++; } } if(l < 0) ans--; cout << ans; }