#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
void print(set <ll> X)
{
    for (ll i:X)
    {
        cout<<i<<" ";
    }
    cout<<endl;
    return;
}
 

ll solve(vector <ll> &A, ll t) {
	int k=(int)A.size();
	ll s=0;
	for (int i=0;i<k;i++) {s+=A[i];}
	if (s<=t) {return s;}
	set <ll> X;
    X.insert(0LL);
    for (int i=0;i<k/2;i++) {
		set <ll> Y;
		ll m=*X.rbegin();
		if (m==t) {return t;}
		for (ll x:X) {
			if (A[i]+x<=t) {
				Y.insert(A[i]+x);
				if (A[i]+x>m) {m=A[i]+x;}
				}
			}
		for (ll y:Y) {X.insert(y);}
 		}
 	set <ll> Z;
    Z.insert(0LL);
    for (int i=k/2;i<k;i++) {
		set <ll> Y;
		ll m=*X.rbegin();
		if (m==t) {return t;}
		for (ll x:Z) {
			if (A[i]+x<=t) {
				Y.insert(A[i]+x);
				if (A[i]+x>m) {m=A[i]+x;}
				}
			}
		for (ll y:Y) {Z.insert(y);}
 		}
 	ll ats=*X.rbegin();
 	ll z=*Z.rbegin();
 	//print(X);
 	//print(Z);
 	ats=max(ats,z);
 	for (ll x:X) {
		auto it=Z.upper_bound(t-x);
		if (it!=Z.begin()) {
			it--;z=*it; if (x+z<=t) {ats=max(ats,x+z);}
			}
		z=*it;
		while (it!=Z.end() && z+x<=t) {ats=max(ats,x+z);it++;if (it!=Z.end()) {z=*it;}}
		}
 	return ats;
	}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll t;
    cin>>n>>t;
    vector <ll> A;
    for (int i=0;i<n;i++) {
		ll a;
		cin>>a;
		if (a<=t) {A.push_back(a);}}
	sort(A.begin(),A.end(),greater<ll>());
	ll ats=solve(A,t);
 	cout<<ats<<endl;
    return 0;
}

/**
 * author: said_v15
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

typedef long long  ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define pb push_back 
#define sc second 
#define f first 
#define kek cout<<"\n";
#define fla cout<<endl;
#define debug(x) cout << #x << " is " << x << '\n';
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define int ll


const ll MOD = (ll) 1e9 + 7;
const ll MOD1 = 998244353;
const int MAXN = 1000010;
const int INF = 1e9;
const ll LL_INF=1e18;
const double pi=3.1415926535;

int divide(int a, int b)
{
          return (a+b-1)/b;
}

int32_t main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 fast;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 
 int questions=1;
 // cin>>questions;
 while(questions--)
 {
         int n,t;
         cin>>n>>t;
         vector<int> v(n);
         forn cin>>v[i];
         int to=n/2;
         int sz=n-to;
         vector<int> sum;
         for(int i=0;i<(1<<to);i++) 
         {
                   int add=0;
                   for(int j=0;j<to;j++) if(i&(1<<j)) add+=v[j];
                   sum.push_back(add);
         }
         sort(all(sum));
         int ans=0;
         for(int i=0;i<(1<<sz);i++) 
         {
                   int add=0;
                   for(int j=to;j<n;j++) if(i&(1<<(j-to))) add+=v[j];
                   int ost=t-add;
                   int near=upper_bound(all(sum),ost)-sum.begin();
                   near--;
                   if(near==-1) continue;
                   ans=max(ans, add+sum[near]);
         }
         cout<<ans;
          
 }

    
 
 // !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)
 

  // cout <<"Runtime is: "<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
}