#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 17, maxN = 4 * N, darr = 1e3 + 17, mod = 1e9 + 7;
int n, k;
int a[N];
int sum;
int ct;
int main() {
  ios_base::sync_with_stdio;
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum < k) {
    cout << n - 1;
    return 0;
  }
  if (sum > k) {
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
      if (k < a[i]) {
        break;
      }
      k -= a[i];
      ct++;
    }
    cout << ct;
    return 0;
  }
  cout << n;
  return 0;
}
