#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
#ifndef DEBUG
#define cerr while(false) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second

ll a[50];
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, t;
	cin>>n>>t;
	int k=n/2;
	vector<int> v1, v2;
	set<ll> sum1, sum2;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i<k) v1.push_back(a[i]);
		else v2.push_back(a[i]);
	}
	int sz1=v1.size(), sz2=v2.size();
	for(int i=0;i<(1<<sz1);i++){
		ll sum=0;
		for(int j=0;j<sz1;j++){
			if(i&(1<<j)){
				sum+=v1[j];
			}
		}
		sum1.insert(sum);
	}
	for(int i=0;i<(1<<sz2);i++){
		ll sum=0;
		for(int j=0;j<sz2;j++){
			if(i&(1<<j)){
				sum+=v2[j];
			}
		}
		sum2.insert(sum);
	}
	ll ans=0;
	for(ll i:sum1){
		if(i>t) continue;
		auto it=sum2.upper_bound(t-i);
		it--;
		ans=max(ans, i+(*it));
	}
	cout<<ans<<endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
  ll n, t, a; cin >> n >> t;
  vector<ll> fa;
  vector<ll> la;
  REP(i,n) {
    cin >> a;
    if (i<20) fa.pb(a);
    else la.pb(a);
  }
  sort(fa.rbegin(), fa.rend());
  sort(la.rbegin(), la.rend());
  ll fsize = fa.size();
  ll lsize = la.size();
  vector<ll> fcan;
  vector<ll> lcan;
  
  REP(i,(1ll<<fsize)) {
    ll val = 0;
    REP(j,fsize){
      if ((i>>j)%2) val += fa[j];
    }
    fcan.pb(val);
  }
  REP(i,(1ll<<lsize)) {
    ll val = 0;
    REP(j,lsize){
      if ((i>>j)%2) val += la[j];
    }
    lcan.pb(val);
  }
  sort(fcan.rbegin(), fcan.rend());
  sort(lcan.begin(), lcan.end());
  ll ans = 0;
  if (lsize==0) {
    sort(fcan.begin(), fcan.end());
    auto ind = upper_bound(fcan.begin(), fcan.end(), t);
    if (ind==fcan.begin()){
      cout << 0 << endl;
    }
    else {
      ind--;
      cout << *ind << endl;
    }
    return 0;
  }
  REP(i,fcan.size()){
    ll nval = fcan[i];
    auto ind = upper_bound(lcan.begin(), lcan.end(), t-nval);
    if (ind!=lcan.begin()) {
      ind--;
      ll maxval = *ind;
      // cout << nval << " " << maxval << endl;
      ans = max(nval+maxval, ans);
    }
  }
  cout << ans << endl;
  return 0;
}