#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fs first
#define sc second
#define endl '\n'


int A, B, C;
double mem[100][100][100];
double dp(int a, int b, int c) {
	if (a >= 100 || b >= 100 || c >= 100)
		return (a - A) + (b - B) + (c - C);

	if (mem[a][b][c] >= 0)
		return mem[a][b][c];

	double ad = (double)a, bd = (double)b, cd = (double)c;

	double sm = 0;
	if(a > 0)
		sm += (ad / (ad + bd + cd)) * dp(a + 1, b, c);
	
	if(b > 0)
		sm += (bd / (ad + bd + cd)) * dp(a, b + 1, c);

	if(c > 0)
		sm += (cd / (ad + bd + cd)) * dp(a, b, c + 1);
	return mem[a][b][c] = sm;
}

set<int> generate_sums(vector<int> A, int cap) {
	int n = A.size();
	set<int> ans;
	for (int i = 0; i < (1 << n); i++) {
		int sm = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j) && sm < cap) {
				sm += A[j];
			}
		}
		ans.insert(sm);
	}
	return ans;
}

void solve() {
	int n, t;
	cin >> n >> t;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	vector<int> F(n / 2), S(n % 2 ? n /2 + 1: n / 2);
	for (int i = 0; i < n / 2; i++) {
		F[i] = A[i];
	}
	for (int i = n / 2; i < n; i++)
		S[i - n / 2] = A[i];
	set<int> fsums = generate_sums(F, t), ssums = generate_sums(S, t);
	int ans = 0;
	for (int val1 : fsums) {
		auto fnd = ssums.upper_bound(t - val1);
		if (fnd == ssums.begin())
			continue;
		fnd--;
		ans = max(ans, *fnd + val1);
	}
	cout << ans << endl;

}

signed main() {
	cin.sync_with_stdio(false); cin.tie(nullptr);
	/*ll t;
	cin >> t;
	while (t--)*/
		solve();
	return 0;
}
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

long long a[100];

long long n,tog;

vector<long long> v1,v2;

long long res;

void dfs1(long long d,long long sum)
{
    if(d==n/2+1)
    {
        v1.push_back(sum);
        res=max(res,sum);
        return;
    }
    if(sum+a[d]<=tog)dfs1(d+1,sum+a[d]);
    dfs1(d+1,sum);
}

void dfs2(long long d,long long sum)
{
    if(d==n+1)
    {
        v2.push_back(sum);
        res=max(res,sum);
        return;
    }
    if(sum+a[d]<=tog)dfs2(d+1,sum+a[d]);
    dfs2(d+1,sum);
}


int main()
{

    cin>>n>>tog;
    for(long long i=1;i<=n;i++) cin>>a[i];
    dfs1(1,0);
    dfs2(n/2+1,0);

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

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

    for(long long i=0;i!=v1.size();i++)
    {
        if(v2.size()==0) break;
        long long l=0,r=v2.size()-1;
        while(l<r)
        {
            long long mid=l+r+1>>1;
            if(v2[mid]<=tog-v1[i]) l=mid;
            else r=mid-1;
        }
        if(v2[l]+v1[i]<=tog)
        {
            res=max(res,v2[l]+v1[i]);
        }
    }
    cout<<res;
}
