#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const long long mxN = 200200;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(20);
  cout << fixed;
  long long n, m;
  cin >> n >> m;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  sort((A).begin(), (A).end());
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (m >= A[i]) ans++, m -= A[i];
  cout << max(ans - (m > 0), 0LL);
}
