#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll
const long double pi = 3.14159265358979323846;
const long double eps = 1e-12;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,T; cin >> n >> T;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> one, two, a1, a2;
    ll m = n / 2;
    rep(i,0,n){
        if (i < m) a1.emplace_back(a[i]);
        else
            a2.emplace_back(a[i]);
    }
    rep(i,0, 1LL << m){
        ll t = 0;
        rep(j, 0, m) {
            if((i >> j) & 1){
                t += a1[j];
            }
        }
        if(t <= T){
            one.emplace_back(t);
        }
    }
    m = n - m;
    rep(i,0,1LL << m){
        ll t = 0;
        rep(j,0,m){
            if((i >> j) & 1){
                t += a2[j];
            }
        }

        if (t <= T) two.emplace_back(t);
    }

    sort(all(one));
    sort(all(two));
    debug(one, two);
    ll ans = 0;
    m = two.size();
    for (auto i : one) {
        ll id = upper_bound(all(two), T - i) - two.begin();
        if(id)chmax(ans, i + two[id-1]);
    }

    cout << ans << endl;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;


mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
}

template<class ForwardIterator> void print_vec(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo < hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

vector<ll> part[2];
ll sums[2][(1<<20)+5];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	ll t;
	cin >> t;
	
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		part[(int)(i >= n/2)].pb(x);
	}
	
	int sizes[] = {n/2,n-n/2};
	
	for (int p = 0; p <= 1; p++) {
		int limit = 1 << sizes[p]; 
		for (int j = 0; j < limit; j++) {
			ll s = 0;
			for (int i = 0; i < sizes[p]; i++) {
				if (TEST(j,i)) {
					s+=part[p][i];
				}
			}
			sums[p][j]=s;
		}
	}
	sort(sums[1], sums[1]+(1 << sizes[1]));
	int limit0 = 1 << sizes[0];
	
	ll best = 0;
	
	for (int i = 0; i < limit0; i++) {
		ll value = sums[0][i];
		if (value == t) {
			cout << t << "\n";
			return 0;
		}
		if (value > t) {
			continue;
		}
		best = max(best,value);
		ll left = t - value;
		auto it = upper_bound(sums[1], sums[1]+(1 << sizes[1]), left);
		if (it == sums[1]) continue;
		it--;
		best = max(best, value + *it);
	}
	cout << best << "\n";
}
