#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 
void sum(vector<ll>&x, vector<ll>&y, int pos, ll total){
    if(pos >= (ll)x.size()) return;
    y.push_back(total);
    sum(x, y, pos+1, total);
    y.push_back(total + x[pos]);
    sum(x, y, pos+1, total + x[pos]);
}
 
int main(){
    ll n, t, ans = 0;
    cin >> n >> t;
    
    vector<ll> a(n);
    vector<ll> b, c, d, e;
    
    for(int i = 0; i < n; i++) cin >> a[i];
 
    for(int i = 0; i < n; i++){
        if(i%2==0) b.push_back(a[i]);
        else c.push_back(a[i]);
    }

    d.push_back(0);
    e.push_back(0);
 
    sum(b, d, 0, 0);
    sum(c, e, 0, 0);

    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    sort(e.begin(), e.end());
    e.erase(unique(e.begin(), e.end()), e.end());

    for(auto x: d){
        if(x > t) continue;
        auto maior = upper_bound(e.begin(), e.end(), t-x);
        if(maior != e.begin() && e.size() != 0) maior--;
        if(x+(*maior) <= t) ans = max(ans, x+(*maior));
    }
    
    cout << ans << '\n';
    return 0;
}
/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n;
LL t;
LL a[44];
vector<LL> solve(int l,int r){
	int len=r-l+1;
	if(len<=0) return vector<LL> (1,0ll);
	vector<LL> rest;
	rep(i,1<<len){
		LL tot=0;
		rep(j,len){
			if((i>>j)&1)
			{
				int is=l+j;
				tot+=a[is];
			}
		}
		rest.PB(tot);
	}
	sort(ALL(rest));	
	return rest;
}
int main(){
	scanf("%d%lld",&n,&t);
	rb(i,1,n)
	scanf("%lld",&a[i]);
	vector<LL> v1,v2;
	int half=(n+1)/2;
	v1=solve(1,half);
	int x=0;
	v2=solve(half+1,n);
	while(v1.back()>t){
		v1.POB();
	}
	LL rest=0;
	while(!v1.empty()){
		LL now=v1.back();
		v1.POB();
		while(x+1<v2.size()&&v2[x+1]+now<=t)
			x++;
		check_max(rest,now+v2[x]);
	}
	cout<<rest<<endl;
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/

