#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const long long mod = 998244353;
long long ksm(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return ans;
}
long long fac[maxn + 3], inv[maxn + 3];
void init() {
  fac[0] = 1ll;
  fac[1] = 1ll;
  for (int i = 2; i <= maxn; i++) fac[i] = fac[i - 1] * i % mod;
  inv[maxn] = ksm(fac[maxn], mod - 2);
  for (int i = maxn - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
int a[maxn];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (k - a[i] >= n - i)
      k -= a[i], ans++;
    else
      break;
  }
  if (k != 0 && ans != 0) ans--;
  cout << ans << endl;
  return 0;
}
