#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  long long ans = 0;
  if (a[0] > k) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    if (k >= a[i])
      k -= a[i], ++ans;
    else
      break;
  }
  if (!k)
    cout << ans << endl;
  else
    cout << ans - 1 << endl;
}
