#include<bits/stdc++.h>
using namespace std;
#define ll long long

void find_sum(vector<ll>& A, ll n, vector<ll>& v)
{
    ll m=A.size();
    for(ll i=0;i<n;i++)
    {
        ll sum=0,x=i,j=m-1;
        while(x)
        {
            if(x&1)
                sum+=A[j];
            j--;
            x/=2;
        }
        v.push_back(sum);
    }
}
int main()
{
    ll N,w; cin>>N>>w;
    ll n=N/2,m=N-n;
    vector<ll> u(n),v(m);
    for(ll i=0;i<n;i++)
        cin>>u[i];
    for(ll i=0;i<m;i++)
        cin>>v[i];
    vector<ll> x,y;
    ll temp=pow(2,n);
    find_sum(u,temp,x);
    temp=pow(2,m);
    find_sum(v,temp,y);
    sort(y.begin(),y.end());
    ll ans=0;
    for(ll i:x)
    {
        if(w<i)
            continue;
        ll index=upper_bound(y.begin(),y.end(),w-i)-y.begin();
        index--;
        if(index!=-1 && i+y[index]>ans)
        {
            ans=i+y[index];
        }
    }
    cout<<ans;
}

#include <bits/stdc++.h>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;
typedef long double ld;
#define BIG 2005


set<ll> solve(vector<ll> B, ll T){
    set<ll> ans;
    for(int i=0;i<B.size();i++){
        if(B[i] > T) continue;
        set<ll> add;
        add.insert(B[i]);
        for(auto tm: ans){
            if(tm+B[i]<=T){
                add.insert(tm+B[i]);
            }
        }
        for(auto tm:add){
            ans.insert(tm);
        }
    }
    return ans;
}

int main() {
    int N;
    ll T;
    cin >> N >> T;
    vector<ll> B;
    vector<ll> C;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        if(i<N/2){
            B.push_back(a);
        }else{
            C.push_back(a);
        }
    }
    // B
    set<ll> ansb = solve(B, T);
    vector<ll> bans;
    for(auto an:ansb){
        bans.push_back(an); //昇順
    }
    // C
    set<ll> ansc = solve(C, T);
    // CとBを組み合わせる
    ll answer = 0;
    for(auto an:ansb){
        answer = max(answer, an);
    }
    for(auto an:ansc){
        if(bans.empty() || bans.size()==0){
            answer = max(answer, an);
            continue;
        }
        int l = 0;
        int r = bans.size()-1;
        if(bans[l]+an>T){
            answer = max(answer, an);
            continue;
        }
        if(bans[r]+an<=T){
            answer = max(answer, an+bans[r]);
            continue;
        }
        while(l+1!=r){
            int mid = (l+r)/2;
            if(an+bans[mid]<=T){
                l = mid;
            }else{
                r = mid;
            }
        }
        answer = max(answer, an+bans[l]);
    }
    printf("%lld\n", answer);
    return 0;
}