#include <bits/stdc++.h>
using namespace std;
using ll     = long long;
using prefix = __attribute__((constructor))void;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807LL;

#define elif           else if
#define def            inline auto
#define func           inline constexpr ll
#define up(i,a,n)      for(ll i=(a),i##_1=(n);i<=i##_1;++i)
#define down(i,a,n)    for(ll i=(a),i##_1=(n);i>=i##_1;--i)
#define rep(i,n)       up(i,0,n-1)
#define append(a)      push_back(a)

func    gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
func    lcm(ll a,ll b) {return a*b/gcd(a,b);}
def     dig(ll a)      {return to_string(a).length();}
prefix  init()         {cin.tie(0),ios::sync_with_stdio(0),cout<<fixed<<setprecision(10);}

signed main(){
    ll N,M,S=0,T=0;
    cin>>N>>M;
    ll A[N];
    rep(i,N)cin>>A[i];
    sort(A,A+N);
    rep(i,N){
        if(M>A[i]){
            M-=A[i];
            S++;
        }
        else if(M==A[i]){
            S++;
            T++;
            break;
        }
        else break;
    }
    if(T==0)S--;
    cout<<max(S,0)<<endl;
}