#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
int N, x;
vector<int> a;
int main() {
  scanf("%d%d", &N, &x);
  a = vector<int>(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int cnt = 0, i;
  for (i = 0; i < N; ++i) {
    if (x < a[i]) break;
    x -= a[i];
    cnt += 1;
  }
  if (x > 0 && cnt != 0) {
    if (i == N)
      cnt -= 1;
    else {
      int last = i;
      bool bExist = false;
      for (; i >= 0; --i) {
        if (last >= N) break;
        if (x + a[i] == a[last]) {
          bExist = true;
          break;
        }
      }
      if (!bExist) cnt -= 1;
    }
  }
  printf("%d\n", cnt);
  return 0;
}
