#include <bits/stdc++.h>
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    char c = getchar();
  }
  while (c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
void print(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 100007;
int a[maxn];
int main() {
  int n = read(), k = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  std::sort(a + 1, a + n + 1);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] <= k)
      k -= a[i], ans++;
    else
      break;
  }
  if (k && ans) ans--;
  print(ans);
  putchar('\n');
}
