
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"
const double PI = acos(-1);

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

lli maxm(lli a, lli b)
{
  return (a >= b ? a : b);
}


lli minm(lli a, lli b)
{
  return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
  lli res = 1;

  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;


    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
  if (r == 0)
    return 1;
  if (r == 1)
    return n;


  lli pro = 1, k = n;
  while (k > r)
  {
    pro *= k;
    pro %= p;
    --k;
  }

  k = 2;
  while (k <= (n - r))
  {
    pro *= power(k, (p - 2), p);
    pro %= p;
    ++k;
  }

  return pro;
}


lli first_big(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = n;
  l = 0;
  r = n - 1;

  while (l <= r) {
    lli m = l + (r - l) / 2;

    if (arr[m] > k) {
      ans = m;
      r = m - 1;
    }

    else
      l = m + 1;
  }

  return ans;
}

lli last_small(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = -1;
  l = 0;
  r = n - 1;

  while (l <= r)
  {
    lli mid = (l + r) / 2;

    if (arr[mid] <= k)
    {
      ans = mid;
      l = mid + 1;
    }
    else
      r = mid - 1;
  }

  return ans;
}

void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void sub_sum(set<lli>&v, vector<lli>a, lli n, lli T)
{
  for (lli i = 0; i < pow(2, n); ++i)
  {
    lli s = 0, x = i;
    for (lli j = 0; j < n; ++j)
    {
      if (x % 2 == 1)
        s += a[j];
      x /= 2;
    }
    if (s <= T)
      v.isrt(s);
  }
}

int main()
{
  c_p_c();

  lli T, n;
  cin >> n >> T;
  if (n <= 20)
  {

    vector<lli>a(n);
    for (lli i = 0; i < n; ++i)
      cin >> a[i];

    set<lli>v;
    sub_sum(v, a, n, T);
    cout << *(prev(v.end())) << endl;

  }
  else
  {
    vector<lli>a(20);
    vector<lli>b(n - 20);
    for (lli i = 0; i < 20; ++i)
      cin >> a[i];

    for (lli j = 0; j < (n - 20); ++j)
      cin >> b[j];

    set<lli>v1;
    set<lli>v2;
    sub_sum(v1, a, 20, T);
    sub_sum(v2, b, n - 20, T);
    lli ans = 0;
    for (auto it : v1)
    {
      lli k = (T - it);
      auto itr = v2.upper_bound(k);
      --itr;
      ans = maxm(ans, it + *itr);
    }
    for (auto it : v2)
    {
      lli k = (T - it);
      auto itr = v1.upper_bound(k);
      --itr;
      ans = maxm(ans, it + *itr);
    }

    cout << ans << endl;
  }

  return 0;
}
#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 105;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,t;
        cin>>n>>t;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        if(n == 1)
        {
            cout<<(a[0] <= t ? a[0] : 0)<<endl;
            return 0;
        }
        set<int> l,r;
        int m = n/2;
        for(int i=0;i<(1LL<<m);i++)
        {
            int tot = 0;
            for(int j=0;j<m;j++)if((i>>j)&1LL)tot += a[j];
            if(tot <= t)l.insert(tot);
        }
        m = n - m;
        for(int i=0;i<(1LL<<m);i++)
        {
            int tot = 0;
            for(int j=0;j<m;j++)if((i>>j)&1LL)tot += a[(n/2) + j];
            if(tot <= t)r.insert(tot);
        }
        int ans = 0;
        if(l.size())ans = max(ans, *l.rbegin());
        if(r.size())ans = max(ans, *r.rbegin());
        for(int x:l)
        {
            int need = t - x;
            auto it = r.lower_bound(need);
            if(it != r.end() && *it > need)
            {
                if(it != r.begin())
                {
                    it--;
                    ans = max(ans, x + *it);
                }
            }
            else if(it == r.end())
            {
                if(it != r.begin())
                {
                    it--;
                    ans = max(ans, x + *it);
                }
            }
            else ans = t;
        }
        cout<<ans<<endl;
    }
    return 0;
}
