#include <bits/stdc++.h>

using namespace std;

using ll  = long long int;
using pii = pair<ll, ll>;

const ll INF = 4e18;
const ll mod = 1e9 + 7;

#define all(a) (a).begin(), (a).end()

// Print for debug
template<class T> ostream& operator<<(ostream &out, vector<T> const &v) { out << "["; for(int i = 0; i < v.size(); i++) {if (i) out << ", "; out << v[i];} return out << "]"; }
template<class T1, class T2> ostream& operator<<(ostream &out, pair<T1, T2> const &p) { return out << "(" << p.first << ", " << p.second << ")"; }

ll nxt() {
    ll x;
    cin >> x;
    return x;
}


ll mmod(ll x, ll y) {
    if (x >= 0)
        return x % y;
    else
        return (y - (-x) % y) % y;
}

ll powmod(ll a, ll n) {
    ll res = 1; a %= mod;
    assert(n >= 0);
    for(; n ; n>>=1) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

void solve() {
    int n, T; cin >> n >> T;
    vector<ll> a(n);
    generate(all(a), nxt);
    vector<ll> A;
    vector<ll> B;
    for (int i = 0; i < (1 << (n / 2)); ++i) {
        ll cursum = 0;
        for (int k = 0; k < n / 2; ++k) {
            if (i & (1 << k)) cursum += a[k];
        }
        A.push_back(cursum);
    }
    for (int i = 0; i < (1 << (n - n / 2)); ++i) {
        ll cursum = 0;
        for (int k = 0; k < n - n / 2; ++k) {
            if (i & (1 << k)) cursum += a[n / 2 + k];
        }
        B.push_back(cursum);
    }
    sort(all(A));
    vector<ll> C;

    auto search = [&](ll x) -> ll {
        int l = -1;
        int r = A.size();
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (x < A[m])
                r = m;
            else
                l = m;
        }
        return l;
    };

    for (auto i : B) {
        int ind = search(T - i);
        if (ind != -1) C.push_back(i + A[ind]);
    }
    sort(all(C));
    cout << C.back() << endl;
}

// #define LOCAL
//#define TESTS

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#ifdef TESTS
    int t; cin >> t;
    while (t--)
#endif
        solve();
    return 0;
}

// Seeing WA2 fills you with DETERMINATION

#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, T;
    cin >> N >> T;
    vector<ll> num(N);
    for (ll i = 0; i < N; i++) {
        cin >> num.at(i);
    }
    // グループ１をビット全探索で全列挙 (前半の半分)
    vector<ll> A;
    for (ll bit = 0; bit < (1 << (N+1) / 2); bit++) {
        ll sum = 0;
        for (ll i = 0; i < ((N+1) / 2); i++) {
            ll mask = 1 << i;
            if (bit & mask) {
                sum += num[i];
            }
        }
        A.push_back(sum);
    }
    // グループ2をビット全探索で全列挙 (後半の半分)
    vector<ll> B;
    for (ll bit = 0; bit < (1 << N / 2); bit++) {
        ll sum = 0;
        for (ll i = 0; i < (N / 2); i++) {
            ll mask = 1 << i;
            if (bit & mask) {
                sum += num[(N+1) / 2 + i];
            }
        }
        B.push_back(sum);
    }
    sort(B.begin(), B.end());

    //rep(i, A.size()) cout << A[i] << " "; cout << endl;
    //rep(i, B.size()) cout << B[i] << " "; cout << endl;

    ll ans = 0;
    for(auto item: A){
        ll key = T-item;
        if(key < 0) continue;
        int ok = -1, ng = B.size();
        int m = (ok+ng)/2;
        while(abs(ok-ng) > 1){
            if(B[m] <= key) ok = m;
            else ng = m;
            m = (ok+ng)/2;
        }
        if(ok != -1) ans = max(ans, item + B[ok]);
    }
    cout << ans << endl;
    return 0;
}