#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long a[45],b[45],d=0,t,n;

void DFS(int c,long long r);
int main()
{
	cin>>n>>t;
	for(int i = 1;i <= n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=n;i>=1;i--)
	{
		b[i]=b[i+1]+a[i];
	}
	DFS(0,t);
	cout << d;
	return 0;
}
void DFS(int c,long long r)
{
	if(c>n)
	{
		return;
	}
	d=max(d,t-r);
	if(r==0)
	{
		cout<<t;
		exit(0);
	}
	if(t-r+b[c+1]<=d)
	{
		return;
	}
	if(r-a[c+1]>=0)
	{
		DFS(c+1,r-a[c+1]);
	}
	DFS(c+1,r);
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=99824453;
vin dx={-1,0,1,0};
vin dy={0,1,0,-1};

int main(){
    int n;ll t;cin>>n>>t;
    vll a(n);rep(i,n)cin>>a[i];
    int k=n/2,h=n-k;
    vll x,y;
    ll sum;
    rep(i,(1<<k)){
        bitset<22> tmp(i);
        sum=0;
        rep(j,k)if(tmp[j])sum+=a[j];
        x.push_back(sum);
    }
    rep(i,(1<<h)){
        bitset<22> tmp(i);
        sum=0;
        rep(j,h)if(tmp[j])sum+=a[k+j];
        y.push_back(sum);
    }
    sort(all(y));
    ll ans=0;
    int l,r,m;
    rep(i,x.size()){
        l=-1;r=y.size();
        while(r-l>1){
            m=(l+r)/2;
            if(y[m]+x[i]>t)r=m;
            else l=m;
        }
        if(l>-1)ans=max(ans,y[l]+x[i]);
    }
    cout<<ans<<endl;
}