#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);

  int n, t; cin >> n >> t;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  uin(n, 20);
  int m = SZ(a) - n;
  set<i64> b;
  for (int nask = 0; nask < (1 << n); ++nask) {
    i64 sum = 0;
    for (int k = 0; k < n; ++k) {
      if (nask >> k & 1) {
        sum += a[k];
      }
    }
    b.insert(sum);
  }
  i64 ans = 0;
  for (int nask = 0; nask < (1 << m); ++nask) {
    i64 sum = 0;
    for (int k = 0; k < m; ++k) {
      if (nask >> k & 1) {
        sum += a[n + k];
      }
    }
    if (sum <= t) {
      uax(ans, sum + *prev(b.upper_bound(t - sum)));
    }
  }
  kek(ans);
}  
#include <bits/stdc++.h>
using namespace std;
#define LL long long

LL n, t, a[45], px, py;
LL x[1100000], y[1100000];

void fx(int p, int ed, LL sum) {
    if (p > ed) {
        x[++px] = sum;
        return;
    }
    fx(p + 1, ed, sum);
    fx(p + 1, ed, sum + a[p]);
    return;
}

void fy(int p, int ed, LL sum) {
    if (p > ed) {
        y[++py] = sum;
        return;
    }
    fy(p + 1, ed, sum);
    fy(p + 1, ed, sum + a[p]);
    return;
}

int main() {
    scanf("%lld%lld", &n, &t);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    fx(1, n / 2, 0LL);
    fy(n / 2 + 1, n, 0LL);
    sort(x + 1, x + px + 1);
    sort(y + 1, y + py + 1);
    LL mx = -1;
    for (int i = 1; i <= px; i++) {
        while (py > 0 && x[i] + y[py] > t) py--;
        if (py == 0) break;
        mx = max(mx, x[i] + y[py]);
    }
    printf("%lld\n", mx);
    return 0;
}