#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18

ll m,ansmax,a[200009];

int n;

bool check(int pos)
{
    int i,j;
    ll ans=0LL;
    for(i=pos,j=n*2-1;i<j;i++,j--)
    {
        if(a[i]+a[j]<m) return false;
        ans=max(ans,a[i]+a[j]-m);
    }
    for(i=0,j=pos-1;i<j;i++,j--)
        ans=max(ans,a[i]+a[j]);
    ansmax=min(ans,ansmax);
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int i,j,lo,hi,mid;
    cin >> n >> m;
    for(i=0;i<2*n;i++)
        cin >> a[i];
    sort(a,a+2*n);

    lo=0;
    hi=n;
    ansmax=inf;
    while(lo<hi)
    {
        mid=(lo+hi)/2;
        if(check(mid*2))
            hi=mid;
        else lo=mid+1;

    }
    check(lo*2);
    check(hi*2);
    cout << ansmax << endl;
}
