#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, sweets, ans;
  cin >> N >> sweets;
  int kibou[N];
  for (int i = 0; i < N; i++) {
    cin >> kibou[i];
  }
  sort(kibou, kibou + N);
  int sum[N];
  sum[0] = kibou[0];
  for (int i = 1; i < N; i++) {
    sum[i] = kibou[i] + sum[i - 1];
  }
  if (sum[N - 1] < sweets) {
    ans = N - 1;
  } else if (sum[0] > sweets) {
    ans = 0;
  } else if (sum[N - 1] == sweets) {
    ans = N;
  } else {
    for (int i = 0; i < N - 1; i++) {
      if (sum[i] <= sweets && sweets < sum[i + 1]) {
        ans = i + 1;
      }
    }
  }
  cout << ans << endl;
}
