#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int k;
  int arr[n];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int no;
    cin >> no;
    arr[i] = no;
  }
  sort(arr, arr + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (k >= arr[i] & n - i > 1) {
      k -= arr[i];
      ans++;
    } else if (k > arr[i] & n - i == 1) {
      break;
    } else if (k = arr[i] & n - i == 1) {
      ans++;
      break;
    }
  }
  cout << ans;
}
