#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> b, c;
  rep(i, n){
    if(i < n/2){
      b.push_back(a.at(i));
    }else{
      c.push_back(a.at(i));
    }
  }
  vector<ll> d;
  rep(bit, 1 << b.size()){
    ll add = 0;
    rep(i, b.size()){
      if((bit & (1 << i)) != 0){
        add += b.at(i);
      }
    }
    d.push_back(add);
  }
  sort(ALL(d));
  d.push_back(LLONG_MAX);
  ll ans = 0;
  rep(bit, 1 << c.size()){
    ll add = 0;
    rep(i, c.size()){
      if((bit & (1 << i)) != 0){
        add += c.at(i);
      }
    }
    if(add > t) continue;
    auto itr = upper_bound(ALL(d), t - add);
    itr--;
    add += *itr;
    ans = max(ans, add);
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

set<int, greater<int>> s;
int n;
vi arr;
int ans = INF;
int m;
void f1(int idx, int cur) {
  if (idx == n / 2) {
    s.emplace(cur);
    return;
  }
  f1(idx + 1, cur);
  f1(idx + 1, cur + arr[idx]);
}

void f2(int idx, int cur) {
  if (idx == n) {
    auto it = s.lower_bound(m - cur);
    if (it != s.end())
      ans = min(ans, m - (cur + *it));
    return;
  }
  f2(idx + 1, cur);
  f2(idx + 1, cur + arr[idx]);
}

// #define MULTIPLE_TEST_CASES
void solve() {
  cin >> n >> m;
  arr.resize(n);
  for (int &x : arr)
    cin >> x;
  f1(0, 0);
  f2(n / 2, 0);
  cout << m - ans << endl;
}

signed main() {
  // const string FILE_NAME = "";
  // freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
  // freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}