#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 100000'00000'00000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

#pragma region Macros
template<typename T1,typename T2> ostream &operator<<(ostream &os,const pair<T1,T2> &p) {
    os << '(' << p.first << ',' << p.second << ')'; return os;
}
template<typename T> ostream &operator<<(ostream &os,const vector<T> &v) {
    os << '[';
    for (auto &e:v) {os << e << ',';}
    os << ']'; return os;
}
// grid searh
const int dy[8] = {-1,0,1,0,-1,-1,1,1};
const int dx[8] = {0,1,0,-1,-1,1,-1,1};
bool IN(int y,int x,int H,int W) {return (0 <= y)&&(y < H)&&(0 <= x)&&(x < W);}
#pragma endregion

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    ll T; cin >> N >> T;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    int M = N/2;
    vector<ll> left,right;
    rep(bit,1<<M) {
        ll val = 0;
        rep(i,M) {
            if ((bit>>i)&1) val += A[i];
        }
        left.push_back(val);
    }
    rep(bit,1<<(N-M)) {
        ll val = 0;
        rep(i,N-M) {
            if ((bit>>i)&1) val += A[i + M];
        }
        right.push_back(val);
    }

    sort(right.begin(),right.end());
    ll ans = 0;
    for (ll val:left) {
        if (val > T) continue;
        int idx = upper_bound(right.begin(),right.end(),T - val) - right.begin();
        --idx;
        if (idx >= 0) ans = max(ans,val + right[idx]);
    }
    cout << ans << '\n';
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> p(n);
  REP(i, n) {
    int a;
    cin >> a;
    p[a].push_back(i);
  }
  REP(i, n) {
    int last = -1;
    p[i].push_back(n);
    EACH(j, p[i]) {
      if (j - last > m) {
        cout << i << endl;
        return;
      }
      last = j;
    }
  }
  cout << n << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif
