#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<P> B(M);
  REP(i, M) cin >> B[i].first >> B[i].second;
  sort(ALL(B));
  set<int> st;
  set<int> ins;
  set<int> del;
  st.insert(N);
  int lastx = 0;
  REP(i, M) {
    int x = B[i].first;
    int y = B[i].second;
    if(x != lastx) {
      for(int z : del) st.erase(z);
      for(int z : ins) st.insert(z);
      del.clear();
      ins.clear();
      lastx = x;
    }
    if(st.find(y) != st.end()) del.insert(y);
    if(st.find(y+1) != st.end() || st.find(y-1) != st.end()) ins.insert(y);
  }
  for(int z : del) st.erase(z);
  for(int z : ins) st.insert(z);
  cout << st.size() << endl;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b, c;
    rep(i,n/2) b.push_back(a[i]);
    for(int i = n/2; i < n; i++) c.push_back(a[i]);
    vector<ll> sum1, sum2;
    int n2 = n/2;
    rep(i,1<<n2){
        ll tmp = 0;
        rep(j,n2) if(i>>j&1) tmp += b[j];
        sum1.push_back(tmp);
    }
    rep(i,1<<(n-n2)){
        ll tmp = 0;
        rep(j,n-n2) if(i>>j&1) tmp += c[j];
        sum2.push_back(tmp);
    }
    ll ans = 0;
    sort(sum1.begin(), sum1.end());
    sort(sum2.begin(), sum2.end());
    rep(i,sum1.size()){
        int id = upper_bound(sum2.begin(), sum2.end(), t-sum1[i]) - sum2.begin();
        if(id == 0) continue;
        ll tmp = sum1[i] + sum2[id-1];
        ans = max(tmp, ans);
    }
   
    cout << ans << endl;
}