#include #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int l, n; cin >> l >> n; vector w(n); for(int i = 0; i < n; i++) { cin >> w[i]; } sort(ALL(w)); int total = 0; int cnt = 0; REP(i, n) { total += w[i]; if(total > l)break; cnt++; } cout << cnt << endl; }