#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    cin >> A[i];
  }
  sort((A).begin(), (A).end());
  long long ans = -1;
  long long sum = 0;
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    sum += A[i];
    if (sum > K) {
      ans = i;
      break;
    }
  }
  if (ans == -1) ans = N;
  cout << ans << endl;
}
