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

int main() {
  int n;
  ll t;
  cin >> n >> t;

  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i];

  vector<ll> sum1, sum2;
  ll sum;
  for (ll bit = ((ll)1 << (n / 2)) - 1; bit >= 0; bit--) {
    sum = 0;
    for (int i = 0; bit >> i; i++) {
      sum += a[i] * ((bit >> i) & 1);
      if (sum > t) break;
    }
    if (sum == t) {
      cout << t;
      return 0;
    } else if (sum <= t) sum1.push_back(sum);
  }
  for (ll bit = ((ll)1 << (n - n / 2)) - 1; bit >= 0; bit--) {
    sum = 0;
    for (int i = 0; bit >> i; i++) {
      sum += a[i + n / 2] * ((bit >> i) & 1);
      if (sum > t) break;
    }
    if (sum == t) {
      cout << t;
      return 0;
    } else if (sum <= t) sum2.push_back(sum);
  }
  sort(sum1.begin(), sum1.end());
  sort(sum2.begin(), sum2.end());

  ll dif, ans = 0;
  auto itr = sum2.end();
  for (auto s : sum1) {
    dif = t - s;
    itr = upper_bound(sum2.begin(), itr, dif);
    if (itr == sum2.begin() && ans < s) ans = s;
    else if (itr != sum2.begin() && ans < s + *(itr - 1)) ans = s + *(itr - 1);
  }
  cout << ans;
}

#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846
 
const int N =2e5+10;
 
int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};



int po(int a, int b) {
int res = 1;
while (b > 0) {
  if (b & 1)
    res = (res%mod * a%mod) % mod;
  a =(a%mod*a%mod) % mod;
  b >>= 1;
}
 return res;
}
 


set<int> cal(vi a) {
   set<int> st;
   
   int n=sz(a);
   for(int i=0;i<(1<<n);i++) {
   	 int sm=0;
      for(int j=0;j<n;j++) {
      	 if(i&(1<<j)) {
      	 	 sm+=a[j];
      	 }
      }
      st.insert(sm);
   }
   return st; 
}



void solve(){  
  int n,k;
  cin>>n>>k;
  vi a(n,0);
  rep(i,0,n) cin>>a[i];
  
  int dn=n/2;
  vi b,c;
  rep(i,0,dn) {
  	 b.pb(a[i]);
  } 

  rep(i,dn,n) {
  	 c.pb(a[i]);
  }

  set<int> x=cal(b);
  set<int> y=cal(c);
  

  int ans=k;

  for(auto to:x) {
  	 auto  it=y.ub(k-to);
  	 if(it==y.begin()) continue;
  	 it--;
  	 int mn=k-to-*it;
  	 if(mn<ans) ans=mn;
  }

  cout<<k-ans<<endl;

} 

 
int32_t main() {
cool;
int t=1;
	 // cin>>t;
	 
while(t--)
   solve();
   
   
   return 0;	   
}