#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mk make_pair
#define ff first
#define ss second
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")  
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007

ll gcd(ll x, ll y){ 
	if(x<y) 
		swap(x,y); 
	if(x%y==0)
		return y;
	return gcd(y, x%y);
}

ll pwm(ll a, ll n){
	ll ans = 1;
	while(n>0){
		if(n%2==1){
			ans = (ans * a)%mod;
		}
		a = (a*a)%mod;
		n /= 2;
	}
	return ans%mod;
}

const int pwn = 100010;
ll pw[pwn];
void pwtwo(){
	pw[0] = 1;
	for(int i=1; i<pwn; i++){
		pw[i] = (pw[i-1]*2)%mod;
	}
}


ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
ll modInverse(ll a, ll m) 
{ 	
	if(a==1)
		return 1;
	//cout<<"mi "<<a<<" "<<m<<" ";
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1){
        //cout << "Inverse doesn't exist"<<endl; 
        return -1;
    }
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        //cout<<res<<endl;
        return res;
        // cout << "modular multiplicative inverse is " << res; 
    } 
} 
  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll fact[1010];
ll init(){
	fact[0] = 1;
	for(int i=1; i<1010; i++)
		fact[i] = (fact[i-1]*i)%mod;
}

ll ncr(ll n, ll r){
	ll ans = fact[n];

	//if(r!=0)
	ans = (ans*modInverse(fact[r], mod))%mod;
	// if(n-r!=0)
	ans = (ans*modInverse(fact[n-r], mod))%mod;

	return ans;
}

bool checkpw(int x){

	if(x<1)
		return false;
	while(x>0){
		if(x==1)
			return true;
		if(x%2!=0)
			return false;
		x /= 2;
	}

	return true;
}

int cross(vector<int> &a, vector<int> &b){
	int as = a.size();
	int bs = b.size();



	// cout<<as<<bs;
	if(a.size()==0 || b.size()==0)
		return 0;

	vector<int> na, nb, nc, nd;	
	int ac, bc, ans, ad, bd;
	ac = bc = ad = bd =  ans = 0;

	// cout<<"xL "<<a.size()<<" "<<b.size()<<endl;
	// cout<<"a: ";
	for(int i=0; i<a.size(); i++){
		// cout<<a[i];
		if(a[i]==0)
			ac++;
		else if(checkpw(a[i]-1))
			ad++;
	}
	// cout<<endl;
	// cout<<"b: ";

	for(int i=0; i<b.size(); i++){	
	// cout<<b[i];	
		
		if(b[i]==0)
			bd++;
		else if(checkpw(b[i]-1))
			bc++;
	}
	// cout<<endl;
	int acr, bcr, bdr, adr;

	// cout<<ad<<bc<<endl;

	ans += min(ac, bc);
	acr = min(ac, bc);
	bcr = min(ac, bc);
	ac -= min(ac, bc);
	bc -= min(ac, bc);

	ans += min(ad, bd);
	adr = min(ad, bd);
	bdr = min(ad, bd);
	ad -= min(ad, bd);
	bd -= min(ad, bd);

	ans += min(ac, bd);
	acr += min(ac, bd);
	bdr += min(ac, bd);
	ac -= min(ac, bd);
	bd -= min(ac, bd);

	// cout<<as<<" "<<bs<<" "<<ans<<endl; 

	if(ac+ad + acr+ adr == as && bc +bd +bcr+bdr ==bs){
		// ac = bc = min(ac, bc);
		// ad = bd = min(ad, bd);
		// ans += min(as, bs);
		

		// ans += min(ac, bc);
		// ans += min(ad, bd);

		// ans += min(ad, bd);

		// ans += min()
		// cout<<a[0]<<" "<<b[0]<<endl;
		// cout<<"tst";
		return ans;
	}
	// ac = bc = min(ac, bc);
	// ad = bd = min(ad, bd);
	// ans += ac;
	// ans += ad;

	// cout<<"t"<<ans;
	// cout<<"xL "<<a.size()<<" "<<b.size()<<endl;
	for(int i=0; i<a.size(); i++){
		if(a[i]==0 && acr>0)
			acr--;
		else if(checkpw(a[i]-1) && adr>0)
			adr--;
		else if(a[i]%2==0)
			na.push_back(a[i]/2);
		else
			nb.push_back(a[i]/2);
	}

	for(int i=0; i<b.size(); i++){
		if(checkpw(b[i]-1) && bcr>0)
			bcr--;
		else if(b[i]==0 && bdr>0)
			bdr--;
		else if(b[i]%2==0)
			nd.push_back(b[i]/2);
		else
			nc.push_back(b[i]/2);
	}
	a.clear();
	b.clear();

	// cout<<"s:" <<na.size()<<nb.size()<<nc.size()<<nd.size()<<endl;
	ans += cross(na, nc) + cross(nb, nd);

	// cout<<as<<" "<<bs<<" "<<ans<<endl;
	return ans;
}

int func(vector<int> &vec, bool carry){
	// cout<<vec.size()<<" "<<carry<<endl;

	if(vec.size()<=1)
		return 0;

	int c= 0;
	for(int i=0; i<vec.size(); i++)
		if(vec[i]==0)
			c++;

	if(c==vec.size())
		return c/2;

	if(carry){
		vector<int> a, b;
		for(int i=0; i<vec.size(); i++){
			if(vec[i]%2==0)
				a.push_back(vec[i]/2);
			else
				b.push_back(vec[i]/2);
		}

		return cross(a, b);
	}
	else{
		vector<int> a, b;
		for(int i=0; i<vec.size(); i++){
			if(vec[i]%2==0)
				a.push_back(vec[i]/2);
			else
				b.push_back(vec[i]/2);
		}

		return func(a, false) + func(b, true);
	}

}
	// if(vec.size()<=1)
	// 	return 0;


	// int ans, c;
	// ans = c =0;
	

	// int p = 0;
	// // for(int i=0; i<)
	// for(int i=0; i<vec.size(); i++){
	// 	if(vec[i] == 0)
	// 		c++;
	// 	else if(vec[i]==1)
	// 		p++;
	// 	else if(vec[i]%2==0)
	// 		a.push_back(vec[i]/2);
	// 	else
	// 		b.push_back(vec[i]/2);
	// }

	// ans = min(p,c);+
	// c -= p;
	// ans += min(0, c/2);

	// vec.clear();
	// ans = c/2 + func(a, false) + func(b);
	// a.clear();
	// b.clear();
	
	// return ans;
// }/

int main(){
	// finput;
	// foutput;
	fast;

	int n, k, i, j, x, m;
	// ll ans;
	string s;
	cin>>n>>m;

	vector<int> vec;

	for(i=0; i<n; i++){
		cin>>x;
		vec.push_back(x);
	}


	sort(vec.begin(), vec.end());

	int ans = 0;
	for(i=0; i<n; i++){
		if(vec[i]<=m){
			m -= vec[i];
			ans++; 
		}
		else
			break;
	}

	if(m>0 && ans==n){
		ans--;
	}
	cout<<ans;

	// vector<int> vec; 
	// for(i=0; i<n; i++){
	// 	cin>>x;
	// 	vec.push_back(x);
	// }

	// sort(vec.begin(), vec.end())''

	// multiset<int> ms;
	// for(i=0; i<vec.size(); i++)
	// 	ms.insert(vec[i]);

	// multiset<int>::iterator it,sit;
	// it = ms.end();
	// it--;
	// while(it!=ms.begin()){
	// 	sit = 
	// }
	// cout<<ans;

	return 0;
}

Measured memory_bytes: 256