#include <bits/stdc++.h>
using namespace std;
using ll = int;
int main() {
  ll n;
  ll k;
  ll arr[n];
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    ll no;
    cin >> no;
    arr[i] = no;
  }
  sort(arr, arr + n);
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (k >= arr[i] & n - i > 1) {
      k -= arr[i];
      ans++;
    } else {
      break;
    }
  }
  cout << ans;
}
