#include <bits/stdc++.h>
using namespace std;
bool Compare(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}
const int INF = 0x3f3f3f3f;
string tostring(long long int Number) {
  string String;
  ostringstream Convert;
  Convert << Number;
  String = Convert.str();
  return String;
}
long long int toint(string String) {
  stringstream Convert(String);
  long long int Number = 0;
  Convert >> Number;
  return Number;
}
long long int MIN() { return INF; }
long long int MAX() { return -INF; }
template <typename T, typename... Args>
inline T MIN(T a, Args... args) {
  return min(a, (T)MIN(args...));
}
template <typename T, typename... Args>
inline T MAX(T a, Args... args) {
  return max(a, (T)MAX(args...));
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int a[n + 1], b[n + 1];
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long int ct = 0;
  if (sum == m)
    cout << n << endl;
  else {
    long long int x = abs(sum - m);
    sort(a + 1, a + n + 1);
    bool ck = false;
    for (int i = 1; i <= n; i++) {
      if (m == a[i]) {
        ck = true;
        cout << 1 << endl;
        return 0;
      }
    }
    long long int xy = 0;
    for (int i = 1; i <= n; i++) {
      xy += a[i];
      if (xy == m) {
        ck = true;
        cout << i << endl;
        break;
      }
    }
    if (ck == false) {
      long long int fg = 0;
      int count = 0;
      int i = 1;
      while (count < n && fg + a[i] <= m) {
        fg += a[i];
        i += 1;
        count++;
      }
      cout << count << endl;
      return 0;
    }
  }
  return 0;
}
