#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define Rep(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n,k;cin>>n>>k;
  int sum=0,ans=0;
  vi v(n);
  rep(i,n){
    cin>>v[i];
    sum+=v[i];
  }
  if(sum<k)cout<<n-1<<endl;
  else if(sum==k)cout<<n<<endl;
  else{
    sort(all(v));
    int c=0;
    rep(i,n){
      c+=v[i];
      if(c>k){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}
