#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (auto& i : a) cin >> i;
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    k -= a[i];
    if (k < 0) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << n << "\n";
  return 0;
}