/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;

#define mod 1000000007
#define pb push_back
#define ll long long int
#define ull unsigned ll
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

/*
const ll infinity = 9e18;

bool compare(ll a,ll b) {return a > b;}
bool compare1(ppl a,ppl b) {return a.ff > b.ff;}
bool compare2(ppl a,ppl b) {return a.ss < b.ss;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}

ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

ll maxi;

vl func(vl v,ll t)
{

    int n = v.size();

    vector<ll> v1;

    for(int i = 1; i < (1<<n); i++)
    {
        int j = i;

        int k = 0;

        ll sum = 0;

        while(j)
        {
            if(j&1)
            {
                sum += v[k];
            }
            k++;
            j = j>>1;
        }

        if(sum <= t)
        {
            maxi = max(maxi,sum);
        }


        v1.pb(sum);
    }

    sort(all(v1));

    return v1;
}


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n,t;
    cin>>n>>t;

    vl a,b;

    forn(i,0,n/2)
    {
        ll x;
        cin>>x;
        a.pb(x);
    }

    forn(i,n/2,n)
    {
        ll x;
        cin>>x;
        b.pb(x);
    }

    maxi = 0;


    vl v1 = func(a,t),v2 = func(b,t);

    for(int i = 0; i < v1.size(); i++)
    {
        ll idx = upper_bound(all(v2),t-v1[i])-v2.begin();
        idx--;

        if(idx >= 0)
        {
            if(v1[i]+v2[idx] <= t)
            {
                maxi = max(maxi,v1[i]+v2[idx]);
            }
        }
    }

    cout<<maxi;










    return 0;
}       
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    ll N, T;
    cin >> N >> T;
    vecl A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
 
    vector<ll> B;


    for (int bit = 0; bit < (1<<(N-N/2)); ++bit) {
        long long sum = 0;
        for (int i = 0; i < N-N/2; ++i) if (bit & (1LL<<i)) sum += A[i+N/2];
        B.push_back(sum);
    }


    sort(B.begin(), B.end());
    B.push_back(1LL<<60);
    
    ll ans = 0;
    for (int bit = 0; bit < (1<<(N/2)); ++bit) {
        long long sum = 0;
        for (int i = 0; i < N/2; ++i) if (bit & (1LL<<i)) sum += A[i];
        if (sum > T) continue;
        auto it = upper_bound(B.begin(), B.end(), T - sum) - B.begin();
        --it;
        chmax(ans, sum + B[it]);
    }
    cout << ans << endl;
}
