#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
using VV = vector<V>;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}
bool isPrime(int a) {
  if (a == 2) return true;
  if (a <= 1 || a % 2 == 0) return false;
  for (int i = 3; i * i <= a; i += 2) {
    if (a % i == 0) return false;
  }
  return true;
}
vector<int> aaa;
bool isOK(int index, int key) {
  if (aaa[index] >= key)
    return true;
  else
    return false;
}
int binary_search(int key) {
  int ng = -1;
  int ok = (int)aaa.size();
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (isOK(mid, key))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void memo() {}
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n + 1, 0);
  for (int i = 0; i < (n); i++) cin >> a[i + 1];
  sort(a.begin(), a.end());
  vector<ll> sum(n + 1);
  for (int i = 0; i < (n); i++) sum[i + 1] += sum[i] + a[i + 1];
  int ans = lower_bound(sum.begin(), sum.end(), x) - sum.begin();
  if (ans <= n && sum[ans] == x) {
    cout << ans << endl;
  } else {
    ans = max(0, ans - 2);
    cout << ans << endl;
  }
  return 0;
}
