#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;



int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    n *= 2;
    vector<int> a(n);
    for(int& x : a) {
      scanf("%d", &x);
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < 2 * n; ++i) {
      a.push_back(a[i]);
    }
    int L = 0, R = m - 1;
    while(L < R) {
      int all_ok = 0;
      vector<int> pre(5 * n + 3);
      vector<int> count_ok(n);
      int answer = (L + R) / 2;
      debug() << imie(answer);
      for(int i = 0; i < n; ++i) {
        auto overflow = [&](int j) {
          int x = a[i] + a[j];
          if(x >= m) {
            x -= m;
          }
          return x;
        };
        int init_overflow = overflow(i + 1);
        bool start_ok = init_overflow <= answer;
        if(start_ok) {
          // first bad
          int low = i + 2, high = i + n;
          while(low < high) {
            int j = (low + high) / 2;
            int tmp = overflow(j);
            if(tmp > answer || tmp < init_overflow) {
              high = j;
            }
            else {
              low = j + 1;
            }
          }
          if(low == i + n || overflow(low) <= answer) {
            // all ok
            ++all_ok;
            debug() << imie(i) "all ok";
          }
          else {
            // last bad
            int first_bad = low;
            low = first_bad - 1;
            high = i + n - 1;
            while(low < high) {
              int j = (low + high + 1) / 2;
              int tmp = overflow(j);
              if(tmp > answer) {
                low = j;
              }
              else {
                high = j - 1;
              }
            }
            assert(low != first_bad - 1);
            int last_bad = low;
            // [first_bad, last_bad]
            debug() << imie(i) imie(first_bad) imie(last_bad);
            
            if(last_bad + 1 < first_bad + n) {
              ++pre[i+last_bad+1];
              --pre[i+first_bad+n];
            }
            //~ for(int k = last_bad + 1; k < first_bad + n; ++k) {
              //~ if(i % 2 != k % 2) {
                //~ ++count_ok[(i+k)/2%n];
                //~ ++count_ok[(i+k+n)/2%n];
              //~ }
            //~ }
          }
        }
        else { // not start_ok
          assert(init_overflow > answer);
          // first good
          int low = i + 2, high = i + n;
          while(low < high) {
            int j = (low + high) / 2;
            int tmp = overflow(j);
            if(tmp >= init_overflow) {
              low = j + 1;
            }
            else {
              high = j;
            }
          }
          if(low == i + n || overflow(low) > answer) {
            // all bad
            //~ ++all_ok;
            debug() << imie(i) "all bad";
          }
          else {
            int first_good = low;
            // last good
            low = first_good - 1;
            high = i + n - 1;
            while(low < high) {
              int j = (low + high + 1) / 2;
              if(overflow(j) <= answer) {
                low = j;
              }
              else {
                high = j - 1;
              }
            }
            int last_good = low;
            assert(first_good <= last_good);
            debug() << imie(i) imie(first_good) imie(last_good);
            ++pre[i+first_good];
            --pre[i+last_good+1];
            //~ for(int k = first_good; k <= last_good; ++k) {
              //~ if(k % 2 != i % 2) {
                //~ ++count_ok[(i+k)/2%n];
                //~ ++count_ok[(i+k+n)/2%n];
              //~ }
            //~ }
          }
        }
      }
      bool anything = false;
      for(int i = 1; i < (int) pre.size(); ++i) {
        pre[i] += pre[i-1];
      }
      //~ vector<int> count_ok(n);
      for(int i = 0; i < (int) pre.size(); ++i) {
        if(i % 2 == 1) {
          int x = pre[i];
          count_ok[i/2%n] += x;
          count_ok[(i/2+n/2)%n] += x;
        }
      }
      for(int& x : count_ok) {
        x += all_ok;
        assert(x <= n);
        if(x == n) {
          anything = true;
        }
      }
      debug() << imie(count_ok) imie(anything);
      //~ return 0;
      if(anything) {
        R = answer;
      }
      else {
        L = answer + 1;
      }
      debug();
      debug();
    }
    printf("%d\n", L);
}


Measured memory_bytes: 7892