#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for(int i=0;i void print(const T &value) { std::cout << value << std::endl; } void yesno(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void YesNo(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } typedef long long ll; typedef unsigned long ul; typedef long double ld; template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll INF = 1000001000; ll mod = 1000000007;//10^9+7 ll power(ll x, ll n, ll mod) {//x^nをmodで割った余り ll res = 1; if (n > 0) { res = power(x, n / 2, mod); if (n % 2 == 0) res = (res * res) % mod; else res = (((res * res) % mod) * x) % mod; } return res; } int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1}; struct Edge { int to, cost; Edge(int to, int cost) : to(to), cost(cost) {}; }; using Graph = vector>;//隣接リスト:G[i]にはiと隣接する頂点が入るよ。 using GraphW = vector>;//重み付きの隣接リスト using P = pair;//BFSで利用。queueに入れる。 using lP = pair; using PP = pair; //dijkstraで利用,priority_queueに入れる。 using p_queue = priority_queue, greater>;//小さい順 class UnionFindTree { public: UnionFindTree(int size) : memberSize(size) { par.resize(size * sizeof(ll)); rnk.resize(size * sizeof(ll)); diff_weight.resize(size * sizeof(ll)); REP(i, size) { par[i] = i; rnk[i] = 0; diff_weight[i] = 0; } } int memberSize; vector par; vector rnk; vector diff_weight; //n個のnodeで初期化する関数 void init(ll n) { REP(i, n) { par[i] = i; rnk[i] = 1; } } //木の根を求める。この際,親は根に更新される。 int find(ll x) { if (par[x] == x) { return x; } else { int r = find(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } //xとyが同じ集合に属するか判定 bool same(ll x, ll y) { return find(x) == find(y); } //xとyの属する集合を融合 void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) { return; } if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) { rnk[x]++; } } } //xの重み ll weight(ll x) { find(x); return diff_weight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } //重みごと更新。weight(y)-weight(x)=wとなるようにする void merge(int x, int y, int w) { w += weight(x); w -= weight(y); x = find(x); y = find(y); if (x == y) { return; } if (rnk[x] < rnk[y]) { par[x] = y; diff_weight[x] = -w; } else { par[y] = x; diff_weight[y] = w; if (rnk[x] == rnk[y]) { rnk[x]++; } } } }; //番号ズレ注意!! int main() { int L, N; cin >> L >> N; int W[N]; REP(i, N) { cin >> W[i]; } sort(W, W + N); int ans = 0; REP(i, N) { L -= W[i]; if (L < 0) { break; } ans++; } cout << ans << endl; }