#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back

using namespace std;
const int N = 1e5+5;
const ll mod = 1e9+7;
ll n, m, t, k, ans, tong, a[N], b[N];

void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    vector<ll> kq;
    k = n / 2;
    for(int i = 1; i < (1<<k); i ++)
    {
        ll total = 0;
        for(int j = 0; j < k; j ++)
        {
            if((i>>j)&1)total += a[j+1];
        }
        if(total <= m)ans = max(ans, total);
        kq.pb(total);
    }
    sort(kq.begin(), kq.end());
    for(int i = 1; i < (1<<(n-k)); i ++)
    {
        ll total = 0;
        for(int j = 0; j < n-k; j ++)
        {
            if((i>>j)&1)total += a[j+k+1];
        }
        t = upper_bound(kq.begin(), kq.end(), m-total)-kq.begin();
        if(t != 0)
        {
            t = kq[t-1];
            ans = max(ans, t+total);
        }
        if(total <= m)ans = max(ans, total);
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)sol();
}
/*
2
10
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10

3
1 2
3 2
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

vl v;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll t, a[50];
  cin>>n>>t;
  REP(i, n){
    cin>>a[i];
  }
  if(n==1){
    cout<<(a[0]<=t ? a[0] : 0)<<'\n';
    return 0;
  }
  int m=n/2;
  int vsize=0;
  REP(i, (1<<(n-m))){
    ll tmp=0;
    REP(j, n-m){
      if(i>>j&1){
        tmp+=a[m+j];
      }
    }
    v.push_back(tmp);
  }
  sort(ALL(v));
  ll ans=0;
  REP(i, (1<<m)){
    ll tmp=0;
    REP(j, m){
      if(i>>j&1){
        tmp+=a[j];
      }
    }
    if(tmp>t){
      continue;
    }
    auto itr=upper_bound(ALL(v), t-tmp);
    CHMAX(ans, *(itr-1)+tmp);
  }
  cout<<ans<<'\n';
  return 0;
}
