#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int x;
  istringstream iss(s);
  iss >> x;
  return x;
}
template <class T>
inline string toString(T x) {
  ostringstream oss;
  oss << x;
  return oss.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
static const auto io_sync_off = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return nullptr;
}();
int main(int argc, char *argv[]) {
  long long n, x;
  cin >> n >> x;
  vector<long long> a;
  long long total = 0;
  for (int i = 0; i < (int)n; ++i) {
    long long y;
    cin >> y;
    if (y <= x) {
      total += y;
      a.push_back(y);
    }
  }
  long long m = int((a).size());
  long long ans = 0;
  if (m == 0)
    ans = 0;
  else if (total == x)
    ans = m;
  else if (total < x)
    ans = m - 1;
  else {
    sort((a).begin(), (a).end());
    long long sum = 0;
    vector<long long> b;
    for (int i = 0; i < (int)m; ++i) {
      if (sum + a[i] <= x) {
        sum += a[i];
        b.push_back(a[i]);
      } else if (sum + a[i] - *b.begin() <= x) {
        sum += a[i] - *b.begin();
        b.push_back(a[i]);
        b.erase(b.begin());
      }
      if (ans < int((b).size()) - ((sum == x) ? 0 : 1)) {
        ans = int((b).size()) - ((sum == x) ? 0 : 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
