#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
const int q = 1e9 + 9;
int main() {
  int n, m, a[5000], ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int m2 = m;
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (m2 >= a[i]) {
      m2 -= a[i];
      ans++;
    }
  }
  if (m2 > 0) ans--;
  if (ans < 1) ans = 0;
  cout << ans << endl;
  return 0;
}
