#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>


using namespace std;

int n,di1,di2,di;
long long t,ans;
long long a[50];
long long sum1[100000006],s,sum2[100000006],sum[10000006];

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }

}

void work()
{
    for(int i=1;i<=n/2;i++)
    {
        sum1[++di1]=a[i];
        for(int j=di1-1;j>=1;j--)
            if(a[i]+sum1[j]<=t)
              sum1[++di1]=a[i]+sum1[j];
    }
    sort(sum1+1,sum1+di1+1);
    for(int i=n/2+1;i<=n;i++)
    {
    	sum2[++di2]=a[i];
        for(int j=di2-1;j>=1;j--)
            if(a[i]+sum2[j]<=t)
              sum2[++di2]=a[i]+sum2[j];
	}
	
	for(int i=1;i<=di2;i++)
	{
		int l=0,r=di1,mid=(l+r)/2;
		while(l<=r)
		{
			mid=(l+r)/2;
			if(sum2[i]+sum1[mid]<=t)
			  l=mid+1;
			else
			  r=mid-1;
		}
		if(sum1[(l+r)/2]+sum2[i]<=t)
			ans=max(ans,sum1[(l+r)/2]+sum2[i]);
	}
	cout<<ans;

}

void work1()
{
    if(s<=t)
    {
        cout<<s;
        return ;
    }
    for(int i=1;i<=n;i++)
    {
        sum[++di]=a[i];
        for(int j=di-1;j>=1;j--)
            if(a[i]+sum[j]<=t)
              sum[++di]=a[i]+sum[j];
    }
    sort(sum+1,sum+di+1);
    for(int i=di;i>=0;i--)
        if(sum[i]<=t)
    {

        cout<<sum[i];
        return ;
    }

}

int main()
{
    ready();
    if(n>20)
      work();
    else
      work1();
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9+7;


int main(){
	ios::sync_with_stdio(false); cin.tie(0);

	ll n, t; cin >> n >> t;
	vi v(n); FOR(i, n) cin >> v[i];
	vector<ll> v1, v2;

	for(int i = 0; i < (1<<(n/2)); i++){
		ll aux = 0;
		for(int j = 0; j < n/2; j++){
			if(i&(1<<j)){
				aux += v[j];
			}
		}
		v1.PB(aux);
	}

	for(int i = 0; i < (1<<((n+1)/2)); i++){
		ll aux = 0;
		for(int j = 0; j < (n+1)/2; j++){
			if(i&(1<<j)){
				aux += v[j+n/2];
			}
		}
		v2.PB(aux);
	}

	sort(all(v2));

	ll ans = 0;
	FOR(i, v1.size()){
		int p = distance(v2.begin(),
						 lower_bound(all(v2), t-v1[i]));
		if(p == (int) v2.size() || v2[p] > t-v1[i]) p--;
		if(p >= 0) ans = max(ans, v1[i] + v2[p]);
	}

	cout << ans << '\n';

	return 0;
}
