#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int M;

bool CanAchieve(const VI &numbers, int bound) {
  const int S = SZ(numbers);

  vector<int> max_small(S);// min_large(S), max_large(S);
  int rptr_small = S - 1;
  for (int lptr = 0; lptr < S; ++lptr) {
    while (rptr_small >= 0 && numbers[lptr] + numbers[rptr_small] > bound) { --rptr_small; }
    //while (rptr_large >= 0 && numbers[lptr] + numbers[rptr_large] > bound + M) { --rptr_large; }
    //while (lptr_large > 0 && numbers[lptr] + numbers[lptr_large-1] >= M) { --lptr_large; }
    max_small[lptr] = rptr_small;
    //max_large[lptr] = rptr_large;
    //min_large[lptr] = lptr_large;
  }

  vector<int> left_large(S), right_large(S);
  int lptr_left = 0, lptr_right = -1;
  for (int rptr = S - 1; rptr >= 0; --rptr) {
    while (lptr_left < S && numbers[rptr] + numbers[lptr_left] < M) { ++lptr_left; }
    while (lptr_right < S-1 && numbers[rptr] + numbers[lptr_right+1] <= M+bound) { ++lptr_right; }
    left_large[rptr] = lptr_left;
    right_large[rptr] = lptr_right;
  }

  debug(numbers, bound, max_small, left_large, right_large);

  int max_left = 0;
  {
    int bound_left = 1e9;
    for (int size_left = 2; size_left <= S; size_left += 2) {
      const int loc = size_left / 2 - 1;
      const int mright = max_small[loc];
      mini(bound_left, mright + loc + 1);
      debug(size_left, loc, mright, bound_left);
      if (size_left <= bound_left) {
        max_left = size_left;
      }
    }
  }

  debug(max_left);

  int max_right = 0;
  {
    int cur_low_right = -1;
    int cur_top_right = 1e9;

    for (int size_right = 2; size_right <= S; size_right += 2) {
      const int loc = S - size_right / 2;
      const int mtop = left_large[loc];
      mini(cur_top_right, loc - mtop + size_right - 1);
      const int mlow = right_large[loc];
      maxi(cur_low_right, loc - mlow + size_right - 1);
      debug(size_right, cur_low_right, cur_top_right);
      if (cur_low_right <= size_right && size_right <= cur_top_right) {
        max_right = size_right;
      }
    }
  }

  debug(max_left, max_right, S);

  return max_left + max_right >= S;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);


  int N;
  cin >> N >> M;
  vector<int> numbers(2 * N);

  for (int &x : numbers) { cin >> x; }
  sort(ALL(numbers));

  int L = -1, R = M - 1;
  while (R - L > 1) {
    const int mid = (L + R) / 2;
    if (CanAchieve(numbers, mid)) {
      R = mid;
    } else {
      L = mid;
    }
  }

  cout << R << "\n";
}



Measured memory_bytes: 8500