#include <bits/stdc++.h>
using namespace std;

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

const double eps = 1e-7;

#define eq(a, b) (abs(a - b) < eps)
#define lt(a, b) ((a + eps) < b)
#define gt(a, b) (a > (b + eps))
#define le(a, b) (a < (b + eps))
#define ge(a, b) ((a + eps) > b)

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const int dt[] = {0, 1, 0, -1, 0};
const int dtx[] = { 0, 0,  1, 1, 1, -1, -1, -1};
const int dty[] = {-1, 1, -1, 0, 1, -1,  0,  1};
const int dtxc[] = {1,  1, 2,  2, -1, -1, -2, -2};
const int dtyc[] = {2, -2, 1, -1,  2, -2,  1, -1};

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
const int mod = 1e9+7;

int n, l;
double lo, hi, best, v[maxn];

bool f(double p) {
    bool ok = true;
    double d = 2.0 * p;
    double last = v[0];
    for (int i = 1; i < n; ++i) {
        ok &= le(v[i] - last, d);
        last = v[i];
    }
    ok &= le(l - last, p);
    return ok;
}

int main() {
    //fastIO();
    cin >> n >> l;

    for (int i = 0; i < n; ++i) {
    	cin >> v[i];
    }

    sort(v, v+n);

    lo = max(v[0], l - v[n-1]);
    hi = l;

    while (abs(hi - lo) > eps) {
        best = (lo + hi)/2.0;
        cout << lo << ' ' << best << ' ' << hi << '\n';
        if (f(best)) hi = best;
        else lo = best;
    }

    cout << fixed << setprecision(9);
    cout << lo << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

const double eps = 1e-7;

#define eq(a, b) (abs(a - b) < eps)
#define lt(a, b) ((a + eps) < b)
#define gt(a, b) (a > (b + eps))
#define le(a, b) (a < (b + eps))
#define ge(a, b) ((a + eps) > b)

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const int dt[] = {0, 1, 0, -1, 0};
const int dtx[] = { 0, 0,  1, 1, 1, -1, -1, -1};
const int dty[] = {-1, 1, -1, 0, 1, -1,  0,  1};
const int dtxc[] = {1,  1, 2,  2, -1, -1, -2, -2};
const int dtyc[] = {2, -2, 1, -1,  2, -2,  1, -1};

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
const int mod = 1e9+7;

int n, l;
double lo, hi, best, v[maxn];

bool f(double p) {
    double d = 2.0 * p;
    double last = -v[0];
    for (int i = 0; i < n; ++i) {
        if (gt(v[i] - last, d)) {
            return false;
        }
        last = v[i];
    }
    if (gt(l - last, d)) return false;
    return true;
}

int main() {
    fastIO();
    cin >> n >> l;

    for (int i = 0; i < n; ++i) {
    	cin >> v[i];
    }

    sort(v, v+n);

    lo = max(v[0], l - v[n-1]);
    hi = l;

    while (!eq(lo, hi)) {
        best = (lo + hi)/2.0;
        if (f(best)) hi = best;
        else lo = best;
    }

    cout << fixed << setprecision(12);
    cout << lo << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

const double eps = 1e-9;

#define eq(a, b) (abs(a - b) < eps)
#define lt(a, b) ((a + eps) < b)
#define gt(a, b) (a > (b + eps))
#define le(a, b) (a < (b + eps))
#define ge(a, b) ((a + eps) > b)

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const int dt[] = {0, 1, 0, -1, 0};
const int dtx[] = { 0, 0,  1, 1, 1, -1, -1, -1};
const int dty[] = {-1, 1, -1, 0, 1, -1,  0,  1};
const int dtxc[] = {1,  1, 2,  2, -1, -1, -2, -2};
const int dtyc[] = {2, -2, 1, -1,  2, -2,  1, -1};

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
const int mod = 1e9+7;

int n, l;
double lo, hi, best, v[maxn];

bool f(double p) {
    bool ok = true;
    double d = 2.0 * p;
    double last = v[0];
    for (int i = 1; i < n; ++i) {
        ok &= le(v[i] - last, d);
        last = v[i];
    }
    ok &= le(l - last, p);
    return ok;
}

int main() {
    fastIO();
    cin >> n >> l;

    for (int i = 0; i < n; ++i) {
    	cin >> v[i];
    }

    sort(v, v+n);

    lo = max(v[0], l - v[n-1]);
    hi = l;

    while (abs(hi - lo) > eps) {
        best = (lo + hi)/2.0;
        if (f(best)) hi = best;
        else lo = best;
    }

    cout << fixed << setprecision(12);
    cout << lo << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
//s<<string;
//s>>x>>comma>>y;
//comma as char;
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vf vector<float>
//#define vb vector<bool>
#define endl "\n"
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MOD 1000000007
#define speedb ios_base::sync_with_stdio(0); cin.tie(0)

int main(){
    speedb;
    long n, l, a;
    cin>>n>>l;
    vi s;
    for(int i = 0; i < n; i++){
		cin>>a;
		s.pb(a);
    }
    sort(all(s));
    float d = 0, temp, start = s[0]-0, en = l-s[n-1];
    for(int i = 1; i < n; i++){
		temp = (float)(s[i] - s[i-1])/2;
		d = max(temp, d);
    }
    d = max(d, en);
    d = max(d, start);
    cout<<fixed<<setprecision(9);
    cout<<d;

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > output){
        output = a;
    }
    if(b > output){
        output = b;
    }
    if(c > output){
        output = c;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    if(*min_element(positions.begin(), positions.end()) == 0){
        cout<<maximum/2;
    }
    else{
        float start = positions[0];
        float middle = maximum/2;
        float last = n - positions[positions.size()-1];
        finalSolution(start, middle, last);
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > output){
        output = a;
    }
    if(b > output){
        output = b;
    }
    if(c > output){
        output = c;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
        }
    }
    cout<<fixed<<setprecision(11);
    float start = positions[0];
    float middle = maximum/2;
    float last = n - positions[positions.size()-1];
    finalSolution(start, middle, last);

}


#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vf vector<float>
#define ll long long
#define l long
#define ss stringstream
#define endl "\n"
#define default_speed ios_base::sync_with_stdio(0); cin.tie(0)
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

int main(){
    default_speed;

    float n, le, p, m = 0;
    cin>>n>>le;
    vf points;
    while(n--){
        cin>>p;
        points.push_back(p);
    }
    sort(points.begin(), points.end());
    cout<<fixed<<setprecision(10);

    //start is not there, end is not there
    if(points[0] != 0 && points[points.size()-1] != le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        if(points[0] > m){
            m = points[0];
        }
        if(le-points[points.size()-1] > m){
            m = le-points[points.size()-1];
        }
        cout<<m;
        return 0;
    }

    //start is there, end is not
    if(points[0] == 0 && points[points.size()-1] != le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        if(le-points[points.size()-1] > m){
            m = le-points[points.size()-1] > m;
        }
        cout<<m;
        return 0;
    }

    //start is not there, end is there
    if(points[0] != 0 && points[points.size()-1] == le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        if(points[0] > m){
            m = points[0];
        }
        cout<<m;
        return 0;
    }

    //start is there, end is there
    if(points[0] == 0 && points[points.size()-1] == le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        cout<<m;
        return 0;
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > output){
        output = a;
    }
    if(b > output){
        output = b;
    }
    if(c > output){
        output = c;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    if(*min_element(positions.begin(), positions.end()) == 0 && d > 1){
        cout<<maximum/2;
        return 0;
    }
    if(d == 1){
        if(n-positions[0] > positions[0]-0){
            cout<<n-positions[0];
            return 0;
        }
        else{
            cout<<positions[0]-0;
            return 0;
        }
        return 0;
    }
    else{
        float start = positions[0];
        float middle = maximum/2;
        float last = n - positions[positions.size()-1];
        finalSolution(start, middle, last);
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > output){
        output = a;
    }
    if(b > output){
        output = b;
    }
    if(c > output){
        output = c;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    if(*min_element(positions.begin(), positions.end()) == 0 && d > 1){
        cout<<maximum/2;
        return 0;
    }
    if(d == 1){
        if(n-d > d-0){
            cout<<n-d;
            return 0;
        }
        else{
            cout<<d-0;
            return 0;
        }
        return 0;
    }
    else{
        float start = positions[0];
        float middle = maximum/2;
        float last = n - positions[positions.size()-1];
        finalSolution(start, middle, last);
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    if(*min_element(positions.begin(), positions.end()) == 0){
        cout<<maximum/2;
    }
    else{
        if(positions[0] > maximum/2){
            cout<<float(positions[0]);
        }
        else{
            cout<<float(maximum/2);
        }
    }

}


#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vf vector<float>
#define ll long long
#define l long
#define ss stringstream
#define endl "\n"
#define default_speed ios_base::sync_with_stdio(0); cin.tie(0)
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

int main(){
    default_speed;

    float n, le, p, m = 0;
    cin>>n>>le;
    vf points;
    while(n--){
        cin>>p;
        points.push_back(p);
    }
    sort(points.begin(), points.end());
    cout<<fixed<<setprecision(10);

    //start is not there, end is not there
    if(points[0] != 0 && points[points.size()-1] != le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        if(points[0] > m){
            m = points[0];
        }
        if(le-points[points.size()-1] > m){
            m = le-points[points.size()-1] > m;
        }
        cout<<m;
        return 0;
    }

    //start is there, end is not
    if(points[0] == 0 && points[points.size()-1] != le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        if(le-points[points.size()-1] > m){
            m = le-points[points.size()-1] > m;
        }
        cout<<m;
        return 0;
    }

    //start is not there, end is there
    if(points[0] != 0 && points[points.size()-1] == le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        if(points[0] > m){
            m = points[0];
        }
        cout<<m;
        return 0;
    }

    //start is there, end is there
    if(points[0] == 0 && points[points.size()-1] == le){
        for(long i = 0; i < points.size()-1; i++){
            if((points[i+1] - points[i])/2 > m){
                m = (points[i+1] - points[i])/2;
            }
        }
        cout<<m;
        return 0;
    }

}


#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vf vector<float>
#define ll long long
#define l long
#define ss stringstream
#define endl "\n"
#define default_speed ios_base::sync_with_stdio(0); cin.tie(0)
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

int main(){
    default_speed;

    float n, le, p, m = 0;
    cin>>n>>le;
    vf points;
    while(n--){
        cin>>p;
        points.push_back(p);
    }
    sort(points.begin(), points.end());
    cout<<fixed<<setprecision(10);

    //start is not there, end is not there
    for(long i = 0; i < points.size()-1; i++){
        if((points[i+1] - points[i])/2 > m){
            m = (points[i+1] - points[i])/2;
        }
    }
    if(points[0] > m){
        m = points[0];
    }
    if(le-points[points.size()-1] > m){
        m = le-points[points.size()-1];
    }
    cout<<m;
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    //0 2 5
    //2,3
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    if(*min_element(positions.begin(), positions.end()) == 0){
        cout<<maximum/2;
    }
    else{
        if(positions[0] > maximum/2){
            cout<<float(positions[0]);
        }
        else{
            cout<<float(maximum/2);
        }
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > output){
        output = a;
    }
    if(b > output){
        output = b;
    }
    if(c > output){
        output = c;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    float start = positions[0];
    float middle = maximum/2;
    float last = n - positions[positions.size()-1];
    finalSolution(start, middle, last);

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > output){
        output = a;
    }
    if(b > output){
        output = b;
    }
    if(c > output){
        output = c;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    if(*min_element(positions.begin(), positions.end()) == 0 && d > 1){
        cout<<maximum/2;
    }
    if(d == 1){
        if(n-d > d-0){
            cout<<n-d;
        }
        else{
            cout<<d-0;
        }
        return 0;
    }
    else{
        float start = positions[0];
        float middle = maximum/2;
        float last = n - positions[positions.size()-1];
        finalSolution(start, middle, last);
    }

}


#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vf vector<float>
#define ll long long
#define l long
#define ss stringstream
#define endl "\n"
#define default_speed ios_base::sync_with_stdio(0); cin.tie(0)
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

int main(){
    default_speed;

    float n, le, p, m = 0;
    cin>>n>>le;
    vf points;
    while(n--){
        cin>>p;
        points.push_back(p);
    }
    sort(points.begin(), points.end());
    cout<<fixed<<setprecision(10);

    //start is not there, end is not there
    for(long i = 0; i < points.size(); i++){
        if((points[i+1] - points[i])/2 > m){
            m = (points[i+1] - points[i])/2;
        }
    }
    if(points[0] > m){
        m = points[0];
    }
    if(le-points[points.size()-1] > m){
        m = le-points[points.size()-1];
    }
    cout<<m;
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef long l;
typedef stringstream ss;
//#ifdef _DEBUG
//freopen("input.txt", "r", stdin);
//#endif

void finalSolution(float a, float b, float c){
    float output = 0;
    if(a > b){
        output = a;
    }
    if(c > a){
        output = a;
    }
    cout<<output;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    long long n, d, input;
    cin>>d>>n;
    vector<long long> positions;
    for(long long i = 0; i < d; i++){
        cin>>input;
        positions.push_back(input);
    }
    sort(positions.begin(), positions.end());
    float maximum = 0, first, second;
    for(long long i = 0; i < positions.size()-1; i++){
        if(abs(positions[i] - positions[i+1]) > maximum){
            maximum = abs(positions[i] - positions[i+1]);
            first = positions[i];
            second = positions[i+1];
        }
    }
    cout<<fixed<<setprecision(11);
    if(*min_element(positions.begin(), positions.end()) == 0){
        cout<<maximum/2;
    }
    else{
        float start = positions[0];
        float middle = maximum/2;
        float last = n - positions[positions.size()-1];
        finalSolution(start, middle, last);
    }

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
//#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;

int32_t main()
{
    fast

   int test=1;
  // cin>>test;
  while(test--)
  {
    int n;
    float mx=0,l,x;
    cin>>n>>l;
    vector<float> v;
    loopf(i,0,n)
    {
      cin>>x;
     v.pb(x);
    }

    sort(all(v));

    mx=max(mx,(v[0]-0));

    loopf(i,0,n-1)
    {
      mx=max(mx,(v[i+1]-v[i])/2);
    }
//cout<<v[n-1];
    mx=max(mx,(v[n-1]-l));

    cout<<fixed<<setprecision(10)<<mx;

  }

}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
#define deb(x) cerr << "(" << #x << " = " << x << ")\n";
#define bp(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

int n, m;
int a[100100];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
    	int l, r;
    	cin >> l >> r;
    	a[l]++;
    	a[r+1]--;
    }
    int mx = 0;
    for(int i = 1; i <= m; ++i) {
    	a[i] += a[i-1];
    	mx = max(mx, a[i]);
    }
    vector < pii > seg;
    for(int i = 1; i <= m; ++i) {
    	if(a[i] == mx) {
    		int j = i;
    		while(j <= m && a[j] == mx)
    			j++;
    		seg.pb(mp(i, j-1));
    		i = j - 1;
    	}
    }
    if(sz(seg) == 1) {
    	cout << m << endl;
    	return 0;
    }
    int ans = m;
    for(int i = 1; i < sz(seg); ++i) {
    	ans -= seg[i].f - seg[i-1].s - 1;
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
#define deb(x) cerr << "(" << #x << " = " << x << ")\n";
#define bp(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

#define ROOT 1,0,n
#define LS v+v,l,mid
#define RS v+v+1,mid+1,r

int n, m;
int a[100100];
int dl[100100], dr[100100];

int t[100100 * 4];

int get(int v, int l, int r, int L, int R) {
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return t[v];
	int mid = (l + r) >> 1;
	return max(get(LS, L, R), get(RS, L, R));
}

void update(int v, int l, int r, int pos, int val) {
	if(l == r) {
		t[v] = max(t[v], val);
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid)
		update(LS, pos, val);
	else
		update(RS, pos, val);
	t[v] = max(t[v+v], t[v+v+1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
    	int l, r;
    	cin >> l >> r;
    	a[l]++;
    	a[r+1]--;
    }
    for(int i = 1; i <= m; ++i) {
    	a[i] += a[i-1];
    }
    for(int i = 1; i <= m; ++i) {
    	dl[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dl[i]);
    }
    memset(t, 0, sizeof t);
    int ans = 0;
    for(int i = m; i >= 1; --i) {
    	dr[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dr[i]);
    	ans = max(ans, dl[i] + dr[i] - 1);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
#define deb(x) cerr << "(" << #x << " = " << x << ")\n";
#define bp(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

#define ROOT 1,0,n
#define LS v+v,l,mid
#define RS v+v+1,mid+1,r

int n, m;
int a[100100];
int dl[100100], dr[100100];

int t[100100 * 4];

int get(int v, int l, int r, int L, int R) {
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return t[v];
	int mid = (l + r) >> 1;
	return max(get(LS, L, R), get(RS, L, R));
}

void update(int v, int l, int r, int pos, int val) {
	if(l == r) {
		t[v] = max(t[v], val);
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid)
		update(LS, pos, val);
	else
		update(RS, pos, val);
	t[v] = max(t[v+v], t[v+v+1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
    	int l, r;
    	cin >> l >> r;
    	a[l]++;
    	a[r+1]--;
    }
    for(int i = 1; i <= m; ++i) {
    	a[i] += a[i-1];
    }
    for(int i = 1; i <= m; ++i) {
    	dl[i] = get(ROOT, 0, a[i]) + 1;
    	update(ROOT, a[i], dl[i]);
    }
    memset(t, 0, sizeof t);
    int ans = 0;
    for(int i = m; i >= 1; --i) {
    	dr[i] = get(ROOT, 0, a[i]) + 1;
    	update(ROOT, a[i], dr[i]);
    	ans = max(ans, dl[i] + dr[i] - 1);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
#define deb(x) cerr << "(" << #x << " = " << x << ")\n";
#define bp(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

#define ROOT 1,1,n
#define LS v+v,l,mid
#define RS v+v+1,mid+1,r

int n, m;
int a[100100];
int dl[100100], dr[100100];

int t[100100 * 4];

int get(int v, int l, int r, int L, int R) {
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return t[v];
	int mid = (l + r) >> 1;
	return max(get(LS, L, R), get(RS, L, R));
}

void update(int v, int l, int r, int pos, int val) {
	if(l == r) {
		t[v] = val;
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid)
		update(LS, pos, val);
	else
		update(RS, pos, val);
	t[v] = max(t[v+v], t[v+v+1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
    	int l, r;
    	cin >> l >> r;
    	a[l]++;
    	a[r+1]--;
    }
    for(int i = 1; i <= m; ++i) {
    	a[i] += a[i-1];
    }
    for(int i = 1; i <= m; ++i) {
    	dl[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dl[i]);
    }
    memset(t, 0, sizeof t);
    int ans = 0;
    for(int i = m; i >= 1; --i) {
    	dr[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dr[i]);
    	ans = max(ans, dl[i] + dr[i] - 1);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
#define deb(x) cerr << "(" << #x << " = " << x << ")\n";
#define bp(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

#define ROOT 1,1,n
#define LS v+v,l,mid
#define RS v+v+1,mid+1,r

int n, m;
int a[100100];
int dl[100100], dr[100100];

int t[100100 * 4];

int get(int v, int l, int r, int L, int R) {
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return t[v];
	int mid = (l + r) >> 1;
	return max(get(LS, L, R), get(RS, L, R));
}

void update(int v, int l, int r, int pos, int val) {
	if(l == r) {
		t[v] = max(t[v], val);
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid)
		update(LS, pos, val);
	else
		update(RS, pos, val);
	t[v] = max(t[v+v], t[v+v+1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
    	int l, r;
    	cin >> l >> r;
    	a[l]++;
    	a[r+1]--;
    }
    for(int i = 1; i <= m; ++i) {
    	a[i] += a[i-1];
    }
    for(int i = 1; i <= m; ++i) {
    	dl[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dl[i]);
    }
    memset(t, 0, sizeof t);
    int ans = 0;
    for(int i = m; i >= 1; --i) {
    	dr[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dr[i]);
    	ans = max(ans, dl[i] + dr[i] - 1);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
#define deb(x) cerr << "(" << #x << " = " << x << ")\n";
#define bp(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

#define ROOT 1,1,n
#define LS v+v,l,mid
#define RS v+v+1,mid+1,r

int n, m;
int a[100100];
int dl[100100], dr[100100];

int t[100100 * 4];

int get(int v, int l, int r, int L, int R) {
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return t[v];
	int mid = (l + r) >> 1;
	return max(get(LS, L, R), get(RS, L, R));
}

void update(int v, int l, int r, int pos, int val) {
	if(l == r) {
		t[v] = val;
		return;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid)
		update(LS, pos, val);
	else
		update(RS, pos, val);
	t[v] = max(t[v+v], t[v+v+1]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0; i < n; ++i) {
    	int l, r;
    	cin >> l >> r;
    	a[l]++;
    	a[r+1]--;
    }
    for(int i = 1; i <= m; ++i) {
    	a[i] += a[i-1];
    }
    for(int i = 1; i <= m; ++i) {
    	dl[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dl[i]);
    }
    memset(t, 0, sizeof t);
    for(int i = m; i >= 1; --i) {
    	dr[i] = get(ROOT, 1, a[i]) + 1;
    	update(ROOT, a[i], dr[i]);
    }
    int ans = 0;
    for(int i = 0; i <= m; ++i) {
    	ans = max(ans, dl[i] + dr[i+1]);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
int segtree[400010];
void update(int loc,int l,int r,int idx,int val)
{
    if(l>idx || r<idx)
    {
        return;
    }
    if(l==idx && idx == r)
    {
        segtree[loc] = val;
        return;
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    update(left,l,mid,idx,val);
    update(right,mid+1,r,idx,val);
    segtree[loc] = max(segtree[left],segtree[right]);
}
int query(int loc,int l,int r,int st,int en)
{
    if(l>r || l>en || r<st)
        return 0;
    if(st<=l && en>=r)
    {
        return segtree[loc];
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    return max(query(left,l,mid,st,en),query(right,mid+1,r,st,en));
}
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,l,r;
    cin>>n>>m;
    int m2 = max(m,n);
    vector<int> pref(m2+2);
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        pref[l]++;
        pref[r+1]--;
    }
    for(int i=0;i<=m2;i++)
        update(1,1,m2,i,0);
    for(int i=1;i<=m2;i++)
    {
        pref[i] += pref[i-1];
        if(pref[i] == 0) continue;
        int cnt = 1 + query(1,1,m2,1,pref[i]);
        update(1,1,m2,pref[i],cnt);
    }
    cout<<query(1,1,m2,1,m2)<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
int segtree1[400010],segtree2[400010];
void update(int segtree[],int loc,int l,int r,int idx,int val)
{
    if(l>idx || r<idx)
    {
        return;
    }
    if(l==idx && idx == r)
    {
        segtree[loc] = val;
        return;
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    update(segtree,left,l,mid,idx,val);
    update(segtree,right,mid+1,r,idx,val);
    segtree[loc] = max(segtree[left],segtree[right]);
}
int query(int segtree[],int loc,int l,int r,int st,int en)
{
    if(l>r || l>en || r<st)
        return 0;
    if(st<=l && en>=r)
    {
        return segtree[loc];
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    return max(query(segtree,left,l,mid,st,en),query(segtree,right,mid+1,r,st,en));
}
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,l,r;
    cin>>n>>m;
    vector<int> pref(m+2);
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        pref[l]++;
        pref[r+1]--;
    }
    for(int i=0;i<=n;i++)
    {
        update(segtree1,1,0,n,i,0);
        update(segtree2,1,0,n,i,0);
    }
    vector<int> prev(m+2,0);
    for(int i=1;i<=m;i++)
    {
        pref[i] += pref[i-1];
        int cnt = 1 + query(segtree1,1,0,n,0,pref[i]);
        update(segtree1,1,0,m,pref[i],cnt);
        prev[i] = cnt;
    }
    int ans = 1;
    for(int i=m;i>=1;i--)
    {
        ans = max(ans,prev[i] + query(segtree2,1,0,n,0,pref[i]));
        int cnt = 1 + query(segtree2,1,0,n,0,pref[i]);
        update(segtree2,1,0,n,pref[i],cnt);
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
int segtree[400010];
void update(int loc,int l,int r,int idx,int val)
{
    if(l>idx || r<idx)
    {
        return;
    }
    if(l==idx && idx == r)
    {
        segtree[loc] = val;
        return;
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    update(left,l,mid,idx,val);
    update(right,mid+1,r,idx,val);
    segtree[loc] = max(segtree[left],segtree[right]);
}
int query(int loc,int l,int r,int st,int en)
{
    if(l>r || l>en || r<st)
        return 0;
    if(st<=l && en>=r)
    {
        return segtree[loc];
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    return max(query(left,l,mid,st,en),query(right,mid+1,r,st,en));
}
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,l,r;
    cin>>n>>m;
    int m2 = max(m,n);
    vector<int> pref(m+2);
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        pref[l]++;
        pref[r+1]--;
    }
    for(int i=0;i<=m2;i++)
        update(1,1,m2,i,0);
    for(int i=1;i<=m2;i++)
    {
        pref[i] += pref[i-1];
        int cnt = 1 + query(1,1,m2,1,pref[i]);
        // cerr<<cnt<<endl;
        update(1,1,m2,pref[i],cnt);
    }
    cout<<query(1,1,m2,1,m2)<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
int segtree1[400010],segtree2[400010];
void update(int segtree[],int loc,int l,int r,int idx,int val)
{
    if(l>idx || r<idx)
    {
        return;
    }
    if(l==idx && idx == r)
    {
        segtree[loc] = val;
        return;
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    update(segtree,left,l,mid,idx,val);
    update(segtree,right,mid+1,r,idx,val);
    segtree[loc] = max(segtree[left],segtree[right]);
}
int query(int segtree[],int loc,int l,int r,int st,int en)
{
    if(l>r || l>en || r<st)
        return 0;
    if(st<=l && en>=r)
    {
        return segtree[loc];
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    return max(query(segtree,left,l,mid,st,en),query(segtree,right,mid+1,r,st,en));
}
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,l,r;
    cin>>n>>m;
    vector<int> pref(m+2);
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        pref[l]++;
        pref[r+1]--;
    }
    for(int i=1;i<=m;i++)
    {
        update(segtree1,1,1,m,i,0);
        update(segtree2,1,1,m,i,0);
    }
    vector<int> prev(m+2,0);
    for(int i=1;i<=m;i++)
    {
        pref[i] += pref[i-1];
        prev[i] = query(segtree1,1,1,m,pref[i],pref[i]);
        int cnt = 1 + query(segtree1,1,1,m,1,pref[i]);
        update(segtree1,1,1,m,pref[i],cnt);
    }
    int ans = 1;
    for(int i=m;i>=1;i--)
    {
        ans = max(ans,query(segtree1,1,1,m,1,pref[i]) + query(segtree2,1,1,m,1,pref[i]));
        update(segtree1,1,1,m,pref[i],prev[i]);
        int cnt = 1 + query(segtree2,1,1,m,1,pref[i]);
        update(segtree2,1,1,m,pref[i],cnt);
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#define int long long
int segtree1[400010],segtree2[400010];
void update(int segtree[],int loc,int l,int r,int idx,int val)
{
    if(l>idx || r<idx)
    {
        return;
    }
    if(l==idx && idx == r)
    {
        segtree[loc] = val;
        return;
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    update(segtree,left,l,mid,idx,val);
    update(segtree,right,mid+1,r,idx,val);
    segtree[loc] = max(segtree[left],segtree[right]);
}
int query(int segtree[],int loc,int l,int r,int st,int en)
{
    if(l>r || l>en || r<st)
        return 0;
    if(st<=l && en>=r)
    {
        return segtree[loc];
    }
    int left = 2*loc, right = 2*loc+1, mid = (l+r)>>1;
    return max(query(segtree,left,l,mid,st,en),query(segtree,right,mid+1,r,st,en));
}
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,l,r;
    cin>>n>>m;
    vector<int> pref(m+2);
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        pref[l]++;
        pref[r+1]--;
    }
    for(int i=0;i<=n;i++)
    {
        update(segtree1,1,0,n,i,0);
        update(segtree2,1,0,n,i,0);
    }
    vector<int> prev(m+2,0);
    for(int i=1;i<=m;i++)
    {
        pref[i] += pref[i-1];
        int cnt = 1 + query(segtree1,1,0,n,0,pref[i]);
        update(segtree1,1,0,n,pref[i],cnt);
        prev[i] = cnt;
    }
    int ans = 1;
    for(int i=m;i>=1;i--)
    {
        ans = max(ans,prev[i] + query(segtree2,1,0,n,0,pref[i]));
        int cnt = 1 + query(segtree2,1,0,n,0,pref[i]);
        update(segtree2,1,0,n,pref[i],cnt);
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forr(i,a,b) for(int i=(a); i <(b); i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i = n-1; i >= 0; i--)
#define zero(v) memset(v, 0, sizeof(v));
#define forall(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v).size()
#define debug(v) cerr << #v << ": " << (v) << endl;
#define debugc(c) forn(i, sz(c)) cerr << #c << "[" << i << "] = " << (c)[i] << endl;

// Para non-increasing, cambiar comparaciones y revisar busq binaria
// Given an array, paint it in the least number of colors so that each color turns to a non-increasing subsequence.
// Solution: Min number of colors = Length of the longest increasing subsequence
const int MAXN = 1e5 + 5;
const int INF = 1e9 + 5;
typedef pair<int,int> ii;
ii d[MAXN+1]; // d[i] = ultimo valor de la subsecuencia de tam i
int padres[MAXN];  // padres
vector<int> RES;// respuesta

int lis(vector<int> &a, vector<int> &dp){ // O(n logn)
    int N = sz(a);
    d[0] = ii(-INF, -1); forn(i, N) d[i+1]=ii(INF, -1);
    forn(i, N){
        int j = upper_bound(d, d+N+1, ii(a[i], INF))-d;
        // if (d[j-1].first < a[i] && a[i] < d[j].first){
            // padres[i]=d[j-1].second;
            d[j] = ii(a[i], i);
        // }
    }

    forn(i, N+1) {
        dp[i] = (d[i].first != INF ? i : 0);
    }

    dforn(i, N+1) if(d[i].first!=INF){
        // rec(d[i].second);// reconstruir rta en RES
        // reverse(RES.begin(), RES.end());
        return i;//longitud
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;

    vector<int> diffarray(m+1, 0);
    forn(i, n) {
        int a, b; cin >> a >> b;
        diffarray[a-1]++;
        diffarray[b]--;
    }

    vector<int> cant(m, 0);
    forn(i, m) {
        cant[i] = (i != 0 ? cant[i-1] : 0) + diffarray[i];
    }

    // forr(i, 0, m) {
    //     cout << cant[i] << " ";
    // }
    // cout << "\n";

    vector<int> creciente(m+1);
    vector<int> decreciente(m+1);

    int lisc = lis(cant, creciente);
    reverse(cant.begin(), cant.end());

    int lisd = lis(cant, decreciente);
    reverse(decreciente.begin(), decreciente.end());

    int maxUnimodal = max(lisc, lisd);
    forn(i, m-1) {
        // debug(creciente[i] + decreciente[i+1])
        maxUnimodal = max(maxUnimodal, creciente[i] + decreciente[i+1]);
    }

    cout << maxUnimodal << "\n";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forr(i,a,b) for(int i=(a); i <(b); i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i = n-1; i >= 0; i--)
#define zero(v) memset(v, 0, sizeof(v));
#define forall(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v).size()
#define debug(v) cerr << #v << ": " << (v) << endl;
#define debugc(c) forn(i, sz(c)) cerr << #c << "[" << i << "] = " << (c)[i] << endl;

// Given an array, paint it in the least number of colors so that each color turns to a non-increasing subsequence.
// Solution: Min number of colors = Length of the longest increasing subsequence

const int MAXN = 1e6 + 5; const int INF = 1e9 + 5;
vector<int> lisRES, lisDP, lisPadre, LIS;

void lisrec_increasing(int i, vector<int> &A){
    if (i == -1) return;
    lisRES.push_back(A[i]);
    lisrec_increasing(lisPadre[i], A);
}
int lis(vector<int> &A) {
    int tam = sz(A);
    LIS.assign(tam, 0);
    lisPadre.assign(tam, -1);
    lisDP.assign(tam, INF);
    int M = 0;
    forn(i, tam) {  // Usar upper_bound para "Longest non-decreasing subsequence"
        int j = upper_bound(lisDP.begin(), lisDP.begin() + M + 1, A[i] ) - lisDP.begin();
        lisDP[j] = A[i];
        LIS[i] = j+1;  // ultimo valor de subsecuencia de tamaño i
        lisPadre[i] = (j == 0 ? -1 : LIS[j-1]);
        M = max(M, j);
    }
    int maxv = 0; int maxi = 0;
    dforn(i, tam) {
        if (LIS[i] > maxv) {
            maxv = LIS[i];
            maxi = i;
        }
    }
    // lisRES.clear();     // Bloque de reconstruccion, no necesario
    // lisrec_increasing(maxi, A); reverse(lisRES.begin(), lisRES.end());;
    return maxv;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;

    vector<int> diffarray(m+1, 0);
    forn(i, n) {
        int a, b; cin >> a >> b;
        diffarray[a-1]++;
        diffarray[b]--;
    }

    vector<int> cant(m, 0);
    forn(i, m) {
        cant[i] = (i != 0 ? cant[i-1] : 0) + diffarray[i];
    }

    int lisc = lis(cant);
    vector<int> creciente = LIS;
    reverse(cant.begin(), cant.end());

    int lisd = lis(cant);
    vector<int> decreciente = LIS;
    reverse(decreciente.begin(), decreciente.end());

    int maxUnimodal = 0;
    forn(i, m) {
        maxUnimodal = max(maxUnimodal, creciente[i] + decreciente[i] - 1);
    }

    cout << maxUnimodal << "\n";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forr(i,a,b) for(int i=(a); i <(b); i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i = n-1; i >= 0; i--)
#define zero(v) memset(v, 0, sizeof(v));
#define forall(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v).size()
#define debug(v) cerr << #v << ": " << (v) << endl;
#define debugc(c) forn(i, sz(c)) cerr << #c << "[" << i << "] = " << (c)[i] << endl;

// Para non-increasing, cambiar comparaciones y revisar busq binaria
// Given an array, paint it in the least number of colors so that each color turns to a non-increasing subsequence.
// Solution: Min number of colors = Length of the longest increasing subsequence
const int MAXN = 1e5 + 5;
const int INF = 1e9 + 5;
typedef pair<int,int> ii;
ii d[MAXN+1]; // d[i] = ultimo valor de la subsecuencia de tam i
int padres[MAXN];  // padres
vector<int> RES;// respuesta

int lis(vector<int> &a, vector<int> &dp){ // O(n logn)
    int N = sz(a);
    d[0] = ii(-INF, -1); forn(i, N) d[i+1]=ii(INF, -1);
    forr(i, 0, N){
        int j = upper_bound(d, d+N+1, ii(a[i], INF))-d;
        if (d[j-1].first <= a[i] && a[i] <= d[j].first){
            // padres[i]=d[j-1].second;
            d[j] = ii(a[i], i);
            dp[j] = i;
        }
    }

    // dforn(i, N+1) {
        // dp[i] = (d[i].first != INF ? i : 0);
    // }

    dforn(i, N+1) if(d[i].first!=INF){
        // rec(d[i].second);// reconstruir rta en RES
        // reverse(RES.begin(), RES.end());
        return i;//longitud
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;

        vector<int> diffarray(m+1, 0);
    forn(i, n) {
        int a, b; cin >> a >> b;
        diffarray[a-1]++;
        diffarray[b]--;
    }

    vector<int> cant(m, 0);
    forn(i, m) {
        cant[i] = (i != 0 ? cant[i-1] : 0) + diffarray[i];
    }

    // forr(i, 0, m) {
    //     cout << cant[i] << " ";
    // }
    // cout << "\n";

    vector<int> creciente(m+1);
    vector<int> decreciente(m+1);

    int lisc = lis(cant, creciente);
    reverse(cant.begin(), cant.end());

    int lisd = lis(cant, decreciente);
    // reverse(decreciente.begin(), decreciente.end());

    // debugc(creciente)
    // debugc(decreciente)

    int maxUnimodal = max(lisc, lisd);
    forn(i, m) {
        // debug(creciente[i] + decreciente[i])
        maxUnimodal = max(maxUnimodal, creciente[i] + decreciente[i+1] - 1);
    }

    cout << maxUnimodal << "\n";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forr(i,a,b) for(int i=(a); i <(b); i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i = n-1; i >= 0; i--)
#define zero(v) memset(v, 0, sizeof(v));
#define forall(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v).size()
#define debug(v) cerr << #v << ": " << (v) << endl;
#define debugc(c) forn(i, sz(c)) cerr << #c << "[" << i << "] = " << (c)[i] << endl;

// Para non-increasing, cambiar comparaciones y revisar busq binaria
// Given an array, paint it in the least number of colors so that each color turns to a non-increasing subsequence.
// Solution: Min number of colors = Length of the longest increasing subsequence
const int MAXN = 1e5 + 5;
const int INF = 1e9 + 5;
typedef pair<int,int> ii;
ii d[MAXN+1]; // d[i] = ultimo valor de la subsecuencia de tam i
int padres[MAXN];  // padres
vector<int> RES;// respuesta

int lis(vector<int> &a, vector<int> &dp){ // O(n logn)
    int N = sz(a);
    d[0] = ii(-INF, -1); forn(i, N-1) d[i+1]=ii(INF, -1);
    int M = 0;
    forr(i, 0, N){
        int j = upper_bound(d, d+M+1, ii(a[i], INF))-d;
        // if (d[j-1].first <= a[i] && a[i] < d[j].first){
            // padres[i]=d[j-1].second;
            d[j] = ii(a[i], i);
            dp[i] = j;
            M = max(M, j);
        // }
    }

    // dforn(i, N+1) {
        // dp[i] = (d[i].first != INF ? i : 0);
    // }

    dforn(i, N+1) if(d[i].first!=INF){
        // rec(d[i].second);// reconstruir rta en RES
        // reverse(RES.begin(), RES.end());
        return i;//longitud
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;

    vector<int> diffarray(m+1, 0);
    forn(i, n) {
        int a, b; cin >> a >> b;
        diffarray[a-1]++;
        diffarray[b]--;
    }

    vector<int> cant(m, 0);
    forn(i, m) {
        cant[i] = (i != 0 ? cant[i-1] : 0) + diffarray[i];
    }

    // forr(i, 0, m) {
    //     cout << cant[i] << " ";
    // }
    // cout << "\n";

    vector<int> creciente(m);
    vector<int> decreciente(m);

    int lisc = lis(cant, creciente);

    // vector<int> LIS(m, 0);
    // vector<int> LISRev(m, 0);
    // vector<int> DP(m, 0);

    // int M = 0;
    // for (int i = 0; i < m; i++) {
    //     int j = upper_bound(DP.begin(), DP.begin() + M + 1, cant[i]) - DP.begin();
    //     LIS[i] = j;
    //     DP[j] = cant[i];
    //     M = max(M, j);
    // }

    // int M = 0;
    // for (int i = m-1; i>=0; i--) {
    //     int j = upper_bound(DP.begin() + 1, DP.begin() + M + 1, cant[i]) - DP.begin();
    //     LISRev[i] = j;
    //     DP[j] = cant[i];
    //     M = max(M, j);
    // }

    // debugc(LISRev);

    reverse(cant.begin(), cant.end());
    int lisd = lis(cant, decreciente);
    reverse(decreciente.begin(), decreciente.end());

    // debugc(creciente)
    // debugc(decreciente)

    // int maxUnimodal = max(lisc, lisd);
    int maxUnimodal = 0;
    forn(i, m) {
        // debug(creciente[i] + decreciente[i])
        maxUnimodal = max(maxUnimodal, creciente[i] + decreciente[i] - 1);
    }

    cout << maxUnimodal << "\n";

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define forr(i,a,b) for(int i=(a); i <(b); i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i = n-1; i >= 0; i--)
#define zero(v) memset(v, 0, sizeof(v));
#define forall(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define sz(v) (int)(v).size()
#define debug(v) cerr << #v << ": " << (v) << endl;
#define debugc(c) forn(i, sz(c)) cerr << #c << "[" << i << "] = " << (c)[i] << endl;

// Para non-increasing, cambiar comparaciones y revisar busq binaria
// Given an array, paint it in the least number of colors so that each color turns to a non-increasing subsequence.
// Solution: Min number of colors = Length of the longest increasing subsequence
const int MAXN = 1e5 + 5;
const int INF = 1e9 + 5;
typedef pair<int,int> ii;
ii d[MAXN+1]; // d[i] = ultimo valor de la subsecuencia de tam i
int padres[MAXN];  // padres
vector<int> RES;// respuesta

int lis(vector<int> &a, vector<int> &dp){ // O(n logn)
    int N = sz(a);
    d[0] = ii(-INF, -1); forn(i, N) d[i+1]=ii(INF, -1);
    forr(i, 0, N){
        int j = upper_bound(d, d+N+1, ii(a[i], INF))-d;
        if (d[j-1].first <= a[i] && a[i] <= d[j].first){
            // padres[i]=d[j-1].second;
            d[j] = ii(a[i], i);
            dp[j] = i;
        }
    }

    // dforn(i, N+1) {
        // dp[i] = (d[i].first != INF ? i : 0);
    // }

    dforn(i, N+1) if(d[i].first!=INF){
        // rec(d[i].second);// reconstruir rta en RES
        // reverse(RES.begin(), RES.end());
        return i;//longitud
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;

        vector<int> diffarray(m+1, 0);
    forn(i, n) {
        int a, b; cin >> a >> b;
        diffarray[a-1]++;
        diffarray[b]--;
    }

    vector<int> cant(m, 0);
    forn(i, m) {
        cant[i] = (i != 0 ? cant[i-1] : 0) + diffarray[i];
    }

    // forr(i, 0, m) {
    //     cout << cant[i] << " ";
    // }
    // cout << "\n";

    vector<int> creciente(m+1);
    vector<int> decreciente(m+1);

    int lisc = lis(cant, creciente);
    reverse(cant.begin(), cant.end());

    int lisd = lis(cant, decreciente);
    // reverse(decreciente.begin(), decreciente.end());

    // debugc(creciente)
    // debugc(decreciente)

    int maxUnimodal = max(lisc, lisd);
    forn(i, m-1) {
        // debug(creciente[i] + decreciente[i])
        maxUnimodal = max(maxUnimodal, creciente[i] + decreciente[i+1] - 1);
    }

    cout << maxUnimodal << "\n";

}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
int l[maxn],r[maxn];
int cnt[maxn],cc[maxn];
int n,m;
int f[maxn],g[maxn];

main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d%d",&l[i],&r[i]);
    for(int i=1;i<=n;i++)cnt[l[i]]++,cnt[r[i]+1]--;
    for(int i=1;i<=m;i++)cnt[i]+=cnt[i-1];
    for(int i=1;i<=m;i++)cc[i]=maxn;
    for(int i=1;i<=m;i++)
    {
        int k=upper_bound(cc+1,cc+m+1,cnt[i])-cc;
        cc[k]=cnt[i];
        f[i]=k;
    }
    for(int i=1;i<=m;i++)cc[i]=maxn;
    for(int i=m;i>=1;i--)
    {
        int k=upper_bound(cc+1,cc+m+1,cnt[i])-cc;
        cc[k]=cnt[i];
        g[i]=k;
    }
    int ans=0;
    //for(int i=1;i<=m;i++)printf("%d ",f[i]);puts("");
    //for(int i=1;i<=m;i++)printf("%d ",g[i]);puts("");
    for(int i=1;i<=m;i++)
    {
        ans=max(ans,f[i]+g[i]-1);
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
int l[maxn],r[maxn];
int cnt[maxn],last[maxn];
int n,m;
int f[maxn],g[maxn],pre[maxn],suf[maxn];
main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d%d",&l[i],&r[i]);
    for(int i=1;i<=n;i++)cnt[l[i]]++,cnt[r[i]+1]--;
    int cur=0;
    for(int i=1;i<=m;i++)
    {
        cur+=cnt[i];//printf("%d ",cur);
        if(cnt[i]>=0)f[i]=f[i-1]+1;
        else f[i]=f[last[cur]]+1;
        last[cur]=i;
        pre[i]=max(pre[i-1],f[i]);
    }
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n;i++)cnt[l[i]-1]--,cnt[r[i]]++;
    for(int i=1;i<=n;i++)last[i]=m+1;
    cur=0;
    for(int i=m;i>=1;i--)
    {
        cur+=cnt[i];//printf("%d ",cur);
        if(cnt[i]>=0)g[i]=g[i+1]+1;
        else g[i]=g[last[cur]]+1;
        last[cur]=i;
        suf[i]=max(suf[i+1],g[i]);
    }
    int ans=0;
    //for(int i=1;i<=m;i++)printf("%d ",f[i]);puts("");
    //for(int i=1;i<=m;i++)printf("%d ",g[i]);puts("");
    for(int i=1;i<=m;i++)
    {
        ans=max(ans,max(f[i]+g[i]-1,pre[i-1]+suf[i+1]));
    }
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                               #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,double>
                                        #define ppap pair<pa,int>

                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-8)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
                                        using namespace std;
                               			class pa3{
                                        	public:
                                        	int x,y,z;
                                        	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                        	bool operator < (const pa3 &p) const{
                                        		if(x!=p.x) return x<p.x;
                                        		if(y!=p.y) return y<p.y;
                                        		 return z<p.z;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                               				bool operator > (const pa3 &p) const{
                                        		if(x!=p.x) return x>p.x;
                                        		if(y!=p.y) return y>p.y;
                                        		 return z>p.z;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa3 &p) const{
                                        		return x==p.x && y==p.y && z==p.z;
                                        	}
                                        		bool operator != (const pa3 &p) const{
                                        			return !( x==p.x && y==p.y && z==p.z);
                                        	}

                                        };

                                        class pa4{
                                        	public:
                                        	double x;
                                        	int y,z,w;
                                        	pa4(double x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                        	bool operator < (const pa4 &p) const{
                                        		if(x!=p.x) return x<p.x;
                                        		if(y!=p.y) return y<p.y;
                                        		if(z!=p.z)return z<p.z;
                                        		return w<p.w;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator > (const pa4 &p) const{
                                        		if(x!=p.x) return x>p.x;
                                        		if(y!=p.y) return y>p.y;
                                        		if(z!=p.z)return z>p.z;
                                        		return w>p.w;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa4 &p) const{
                                        		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                        	}

                                        };
                                        class pa2{
                                        	public:
                                        	int x,y;
                                        	pa2(int x=0,int y=0):x(x),y(y) {}
                                        	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                        	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                        	pa2 operator * (int a) {return pa2(x*a,y*a);}
                                        	bool operator < (const pa2 &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator > (const pa2 &p) const{
                                        		return x != p.x ? x>p.x: y>p.y;
                                        	}
                                        	bool operator == (const pa2 &p) const{
                                        		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                        	}
                                        	bool operator != (const pa2 &p) const{
                                        		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                        	}

                                        };

                                               #define ppa pair<int,pas>
                                        class Point{
                                        	public:
                                        	double x,y;
                                        	Point(double x=0,double y=0):x(x),y(y) {}
                                        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
                                        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
                                        	Point operator * (double a) {return Point(x*a,y*a);}
                                        	Point operator / (double a) {return Point(x/a,y/a);}
                                        	double absv() {return sqrt(norm());}
                                        	double norm() {return x*x+y*y;}
                                        	bool operator < (const Point &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const Point &p) const{
                                        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
                                        	}
                                        };
                                        typedef Point Vector;
                                 #define pl pair<int,pas>
                                        struct Segment{
                                        Point p1,p2;
                                        };
                                         double dot(Vector a,Vector b){
                                        	return a.x*b.x+a.y*b.y;
                                        }
                                        double cross(Vector a,Vector b){
                                        	return a.x*b.y-a.y*b.x;
                                        }

            bool parareru(Point a,Point b,Point c,Point d){
            //	if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
            	return abs(cross(a-b,d-c))<EPS;
            }
            double distance_ls_p(Point a, Point b, Point c) {
              if ( dot(b-a, c-a) < EPS ) return (c-a).absv();
              if ( dot(a-b, c-b) < EPS ) return (c-b).absv();
              return abs(cross(b-a, c-a)) / (b-a).absv();
            }
            bool is_intersected_ls(Segment a,Segment b) {
            	if(a.p1==b.p1||a.p2==b.p1||a.p1==b.p2||a.p2==b.p2) return false;
            	if(parareru((a.p2),(a.p1),(a.p1),(b.p2))&&parareru((a.p2),(a.p1),(a.p1),(b.p1))){
            //		cout<<"sss"<<endl;
            		if(dot(a.p1-b.p1,a.p1-b.p2)<EPS) return true;
            		if(dot(a.p2-b.p1,a.p2-b.p2)<EPS) return true;
            		if(dot(a.p1-b.p1,a.p2-b.p1)<EPS) return true;
            		if(dot(a.p1-b.p2,a.p2-b.p2)<EPS) return true;
            		return false;
            	}
              else return ( cross(a.p2-a.p1, b.p1-a.p1) * cross(a.p2-a.p1, b.p2-a.p1) < EPS ) && ( cross(b.p2-b.p1, a.p1-b.p1) * cross(b.p2-b.p1, a.p2-b.p1) < EPS );
            }

            double segment_dis(Segment a,Segment b){
            	if(is_intersected_ls(a,b))return 0;
            	double r=distance_ls_p(a.p1, a.p2, b.p1);
            	r=min(r,distance_ls_p(a.p1, a.p2, b.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p1));
            	return r;
            }
            Point intersection_ls(Segment a, Segment b) {
              Point ba = b.p2-b.p1;
              double d1 = abs(cross(ba, a.p1-b.p1));
              double d2 = abs(cross(ba, a.p2-b.p1));
              double t = d1 / (d1 + d2);

              return a.p1 + (a.p2-a.p1) * t;
            }

                            string itos( int i ) {
                            ostringstream s ;
                            s << i ;
                            return s.str() ;
                            }

                            int gcd(int v,int b){
                            	if(v>b) return gcd(b,v);
                            	if(v==b) return b;
                            	if(b%v==0) return v;
                            	return gcd(v,b%v);
                            }

                            double distans(double x1,double y1,double x2,double y2){
                            	double rr=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
                            	return sqrt(rr);

                            }
             /*
            int pr[1000010];
            int inv[1000010];

            int beki(int wa,int rr,int warukazu){
            	if(rr==0) return 1%warukazu;
            	if(rr==1) return wa%warukazu;
            	if(rr%2==1) return (beki(wa,rr-1,warukazu)*wa)%warukazu;
            	int zx=beki(wa,rr/2,warukazu);
            	return (zx*zx)%warukazu;
            }
double bekid(double w,int r){
	if(r==0) return 1.0;
	if(r==1) return w;
	if(r%2) return bekid(w,r-1)*w;
	double f=bekid(w,r/2);
	return f*f;
}

			int comb(int nn,int rr){
				int r=pr[nn]*inv[rr];
				r%=inf;
				r*=inv[nn-rr];
				r%=inf;
				return r;
			}

            void gya(int ert){
            	pr[0]=1;
            	for(int i=1;i<=ert;i++){
            		pr[i]=(pr[i-1]*i)%inf;
            	}
           	for(int i=0;i<=ert;i++) inv[i]=beki(pr[i],inf-2,inf);

            }
            */
			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
             //sort(ve.begin(),ve.end(),greater<int>());
                                     //----------------kokomade tenpure------------
            //vector<double> ans(100000000),ans2(100000000)

struct Segmax{
	//       1
	//   2        3
	// 4   5   6    7

	private:
	public:

	// (1<<15)=32768
	// 1<<16 = 65536
	// 1<<17 = 131072
	// 1<<18 = 262144

	int cor=(1<<17);

	vector<pa> vec;

	void shoki1(){

		vec.resize(2*cor+3, mp(0,0));
		for(int i=cor;i<2*cor;i++)vec[i].second=i-cor;
	}
		void shoki2(){
			for(int i=cor-1;i>0;i--) {
				if(vec[2*i].first>=vec[2*i+1].first) vec[i]=vec[2*i];
				else vec[i]=vec[2*i+1];
			}
		}

	void updadd(int x,int w){
		//x ���ڂ� w���Z
		x+=cor;
		vec[x].first+=w;
		while(1){
			x/=2;
			if(x==0) break;
			if(vec[2*x].first>=vec[2*x+1].first) vec[x]=vec[2*x];
			else vec[x]=vec[2*x+1];
		}

	}

	void updchan(int x,int w){
		//x���ڂ�w�ɕύX
		x+=cor;
		vec[x].first=w;
		while(1){
			x/=2;
			if(x==0) break;
			if(vec[2*x].first>=vec[2*x+1].first) vec[x]=vec[2*x];
			else vec[x]=vec[2*x+1];
		}

	}
	// [a,b)
	// k-th node
	// k no kukanha [l,r)
	pa segmax(int a,int b,int k=1,int l=0,int r=-10){
		if(r<0)r=cor;

	//	cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;

		if(a<=l && r<=b){
			return vec[k];
		}
		if(r<=a || b<=l){
			return mp(-(1ll<<31),-1);
		}

		pa v1=segmax(a,b,k*2,l,(l+r)/2),v2=segmax(a,b,k*2+1,(l+r)/2,r);

		if(v1.first>=v2.first)return v1;
		else return v2;
	}

};
int imo[100010];
int hi[100010],mi[100010];
Segmax sm,sm2;
signed main(){
//ios::sync_with_stdio(false);
int n,m;
	sm.shoki1();
	sm.shoki2();
	sm2.shoki1();
	sm2.shoki2();
	cin>>n>>m;
	for(int i=0;i<n;i++){
	int y,yy;
		cin>>y>>yy;
		yy++;
		imo[y]++;
		imo[yy]--;

	}
	for(int i=1;i<=100002;i++)imo[i]+=imo[i-1];

	for(int i=1;i<=m;i++){
		pa z=sm.segmax(0,imo[i]+1);
		hi[i]=1+z.first;
		sm.updchan(imo[i],hi[i]);
	//	cout<<hi[i]<<endl;
	}

	for(int i=m;i>0;i--){
		pa z=sm2.segmax(0,imo[i]+1);
		mi[i]=1+z.first;
		sm2.updchan(imo[i],mi[i]);
	//	cout<<mi[i]<<endl;
	}
	int ans=0;
	for(int i=1;i<=m;i++)ans=max(ans,hi[i]+mi[i]-1);
	cout<<ans<<endl;
	return 0;
        }


#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                               #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,double>
                                        #define ppap pair<pa,int>

                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-8)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
                                        using namespace std;
                               			class pa3{
                                        	public:
                                        	int x,y,z;
                                        	pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
                                        	bool operator < (const pa3 &p) const{
                                        		if(x!=p.x) return x<p.x;
                                        		if(y!=p.y) return y<p.y;
                                        		 return z<p.z;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                               				bool operator > (const pa3 &p) const{
                                        		if(x!=p.x) return x>p.x;
                                        		if(y!=p.y) return y>p.y;
                                        		 return z>p.z;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa3 &p) const{
                                        		return x==p.x && y==p.y && z==p.z;
                                        	}
                                        		bool operator != (const pa3 &p) const{
                                        			return !( x==p.x && y==p.y && z==p.z);
                                        	}

                                        };

                                        class pa4{
                                        	public:
                                        	double x;
                                        	int y,z,w;
                                        	pa4(double x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
                                        	bool operator < (const pa4 &p) const{
                                        		if(x!=p.x) return x<p.x;
                                        		if(y!=p.y) return y<p.y;
                                        		if(z!=p.z)return z<p.z;
                                        		return w<p.w;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator > (const pa4 &p) const{
                                        		if(x!=p.x) return x>p.x;
                                        		if(y!=p.y) return y>p.y;
                                        		if(z!=p.z)return z>p.z;
                                        		return w>p.w;
                                        		//return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const pa4 &p) const{
                                        		return x==p.x && y==p.y && z==p.z &&w==p.w;
                                        	}

                                        };
                                        class pa2{
                                        	public:
                                        	int x,y;
                                        	pa2(int x=0,int y=0):x(x),y(y) {}
                                        	pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
                                        	pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
                                        	pa2 operator * (int a) {return pa2(x*a,y*a);}
                                        	bool operator < (const pa2 &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator > (const pa2 &p) const{
                                        		return x != p.x ? x>p.x: y>p.y;
                                        	}
                                        	bool operator == (const pa2 &p) const{
                                        		return abs(x-p.x)==0 && abs(y-p.y)==0;
                                        	}
                                        	bool operator != (const pa2 &p) const{
                                        		return !(abs(x-p.x)==0 && abs(y-p.y)==0);
                                        	}

                                        };

                                               #define ppa pair<int,pas>
                                        class Point{
                                        	public:
                                        	double x,y;
                                        	Point(double x=0,double y=0):x(x),y(y) {}
                                        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
                                        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
                                        	Point operator * (double a) {return Point(x*a,y*a);}
                                        	Point operator / (double a) {return Point(x/a,y/a);}
                                        	double absv() {return sqrt(norm());}
                                        	double norm() {return x*x+y*y;}
                                        	bool operator < (const Point &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const Point &p) const{
                                        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
                                        	}
                                        };
                                        typedef Point Vector;
                                 #define pl pair<int,pas>
                                        struct Segment{
                                        Point p1,p2;
                                        };
                                         double dot(Vector a,Vector b){
                                        	return a.x*b.x+a.y*b.y;
                                        }
                                        double cross(Vector a,Vector b){
                                        	return a.x*b.y-a.y*b.x;
                                        }

            bool parareru(Point a,Point b,Point c,Point d){
            //	if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
            	return abs(cross(a-b,d-c))<EPS;
            }
            double distance_ls_p(Point a, Point b, Point c) {
              if ( dot(b-a, c-a) < EPS ) return (c-a).absv();
              if ( dot(a-b, c-b) < EPS ) return (c-b).absv();
              return abs(cross(b-a, c-a)) / (b-a).absv();
            }
            bool is_intersected_ls(Segment a,Segment b) {
            	if(a.p1==b.p1||a.p2==b.p1||a.p1==b.p2||a.p2==b.p2) return false;
            	if(parareru((a.p2),(a.p1),(a.p1),(b.p2))&&parareru((a.p2),(a.p1),(a.p1),(b.p1))){
            //		cout<<"sss"<<endl;
            		if(dot(a.p1-b.p1,a.p1-b.p2)<EPS) return true;
            		if(dot(a.p2-b.p1,a.p2-b.p2)<EPS) return true;
            		if(dot(a.p1-b.p1,a.p2-b.p1)<EPS) return true;
            		if(dot(a.p1-b.p2,a.p2-b.p2)<EPS) return true;
            		return false;
            	}
              else return ( cross(a.p2-a.p1, b.p1-a.p1) * cross(a.p2-a.p1, b.p2-a.p1) < EPS ) && ( cross(b.p2-b.p1, a.p1-b.p1) * cross(b.p2-b.p1, a.p2-b.p1) < EPS );
            }

            double segment_dis(Segment a,Segment b){
            	if(is_intersected_ls(a,b))return 0;
            	double r=distance_ls_p(a.p1, a.p2, b.p1);
            	r=min(r,distance_ls_p(a.p1, a.p2, b.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p1));
            	return r;
            }
            Point intersection_ls(Segment a, Segment b) {
              Point ba = b.p2-b.p1;
              double d1 = abs(cross(ba, a.p1-b.p1));
              double d2 = abs(cross(ba, a.p2-b.p1));
              double t = d1 / (d1 + d2);

              return a.p1 + (a.p2-a.p1) * t;
            }

                            string itos( int i ) {
                            ostringstream s ;
                            s << i ;
                            return s.str() ;
                            }

                            int gcd(int v,int b){
                            	if(v>b) return gcd(b,v);
                            	if(v==b) return b;
                            	if(b%v==0) return v;
                            	return gcd(v,b%v);
                            }

                            double distans(double x1,double y1,double x2,double y2){
                            	double rr=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
                            	return sqrt(rr);

                            }
             /*
            int pr[1000010];
            int inv[1000010];

            int beki(int wa,int rr,int warukazu){
            	if(rr==0) return 1%warukazu;
            	if(rr==1) return wa%warukazu;
            	if(rr%2==1) return (beki(wa,rr-1,warukazu)*wa)%warukazu;
            	int zx=beki(wa,rr/2,warukazu);
            	return (zx*zx)%warukazu;
            }
double bekid(double w,int r){
	if(r==0) return 1.0;
	if(r==1) return w;
	if(r%2) return bekid(w,r-1)*w;
	double f=bekid(w,r/2);
	return f*f;
}

			int comb(int nn,int rr){
				int r=pr[nn]*inv[rr];
				r%=inf;
				r*=inv[nn-rr];
				r%=inf;
				return r;
			}

            void gya(int ert){
            	pr[0]=1;
            	for(int i=1;i<=ert;i++){
            		pr[i]=(pr[i-1]*i)%inf;
            	}
           	for(int i=0;i<=ert;i++) inv[i]=beki(pr[i],inf-2,inf);

            }
            */
			//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
             //sort(ve.begin(),ve.end(),greater<int>());
                                     //----------------kokomade tenpure------------
            //vector<double> ans(100000000),ans2(100000000)
const int MAXN=10000;
struct Segmax{
	//       1
	//   2        3
	// 4   5   6    7

	private:
	public:

	// (1<<15)=32768
	// 1<<16 = 65536
	// 1<<17 = 131072
	// 1<<18 = 262144

	int cor=(1<<17);

	vector<pa> vec;

	void shoki1(){

		vec.resize(2*cor+3, mp(0,0));
		for(int i=cor;i<2*cor;i++)vec[i].second=i-cor;
	}
		void shoki2(){
			for(int i=cor-1;i>0;i--) {
				if(vec[2*i].first>=vec[2*i+1].first) vec[i]=vec[2*i];
				else vec[i]=vec[2*i+1];
			}
		}

	void updadd(int x,int w){
		//x ���ڂ� w���Z
		x+=cor;
		vec[x].first+=w;
		while(1){
			x/=2;
			if(x==0) break;
			if(vec[2*x].first>=vec[2*x+1].first) vec[x]=vec[2*x];
			else vec[x]=vec[2*x+1];
		}

	}

	void updchan(int x,int w){
		//x���ڂ�w�ɕύX
		x+=cor;
		vec[x].first=w;
		while(1){
			x/=2;
			if(x==0) break;
			if(vec[2*x].first>=vec[2*x+1].first) vec[x]=vec[2*x];
			else vec[x]=vec[2*x+1];
		}

	}
	// [a,b)
	// k-th node
	// k no kukanha [l,r)
	pa segmax(int a,int b,int k=1,int l=0,int r=-10){
		if(r<0)r=cor;

	//	cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;

		if(a<=l && r<=b){
			return vec[k];
		}
		if(r<=a || b<=l){
			return mp(-(1ll<<31),-1);
		}

		pa v1=segmax(a,b,k*2,l,(l+r)/2),v2=segmax(a,b,k*2+1,(l+r)/2,r);

		if(v1.first>=v2.first)return v1;
		else return v2;
	}

};
int imo[100010];
int hi[100010],mi[100010];
Segmax sm,sm2;
signed main(){
//ios::sync_with_stdio(false);
int n,m;
	sm.shoki1();
	sm.shoki2();
	sm2.shoki1();
	sm2.shoki2();
	cin>>n>>m;
	for(int i=0;i<n;i++){
	int y,yy;
		cin>>y>>yy;
		yy++;
		imo[y]++;
		imo[yy]--;

	}
	for(int i=1;i<=100002;i++)imo[i]+=imo[i-1];

	for(int i=1;i<=m;i++){
		pa z=sm.segmax(0,imo[i]+1);
		hi[i]=1+z.first;
		sm.updchan(imo[i],hi[i]);
	//	cout<<hi[i]<<endl;
	}

	for(int i=m;i>0;i--){
		pa z=sm2.segmax(0,imo[i]+1);
		mi[i]=1+z.first;
		sm2.updchan(imo[i],mi[i]);
	//	cout<<mi[i]<<endl;
	}
	int ans=0;
	for(int i=1;i<=m;i++)ans=max(ans,hi[i]+mi[i])-1;
	cout<<ans<<endl;
	return 0;
        }


#include <bits/stdc++.h>

using namespace std;

const int NMAX = 100010;

int N, M;
int V[NMAX], LIS[NMAX], DP[NMAX];

int fastLog2(int value) {
	int answer = 0;
	for (int i = 4; i >= 0; --i) {
		if (value >> (answer | (1 << i))) {
			answer |= 1 << i;
		}
	}
	return answer;
}

int main() {
//	assert(freopen("debug.in", "r", stdin));
//	assert(freopen("debug.out", "w", stdout));

	cin >> N >> M;
	while (N--) {
		int x, y;
		cin >> x >> y;
		++V[x];
		--V[y + 1];
	}

	for (int i = 2; i <= M; ++i)
		V[i] += V[i - 1];

	int len = 1;
	LIS[1] = V[1];
	for (int i = 2; i <= M; ++i) {
		int pos = 0;
		for (int j = fastLog2(len); j >= 0; --j) {
			if ((pos | (1 << j)) <= len && LIS[pos | (1 << j)] <= V[i]) {
				pos |= 1 << j;
			}
		}
		LIS[++pos] = V[i];
		if (pos > len)
			len = pos;
		DP[i] = pos;
	}

	int answer = 0;

	reverse(V + 1, V + M + 1);
	len = 1;
	LIS[1] = V[1];
	for (int i = 2; i <= M; ++i) {
		int pos = 0;
		for (int j = fastLog2(len); j >= 0; --j) {
			if ((pos | (1 << j)) <= len && LIS[pos | (1 << j)] <= V[i]) {
				pos |= 1 << j;
			}
		}
		LIS[++pos] = V[i];
		if (pos > len)
			len = pos;

		answer = max(answer, DP[M - i + 1] + pos - 1);
	}

	cout << answer << '\n';

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NMAX = 100010;

int N, M;
int V[NMAX], LIS[NMAX];

int fastLog2(int value) {
	int answer = 0;
	for (int i = 4; i >= 0; --i) {
		if (value >> (answer | (1 << i))) {
			answer |= 1 << i;
		}
	}
	return answer;
}

int main() {
//	assert(freopen("debug.in", "r", stdin));
//	assert(freopen("debug.out", "w", stdout));

	cin >> N >> M;
	while (N--) {
		int x, y;
		cin >> x >> y;
		++V[x];
		--V[y + 1];
	}

	for (int i = 2; i <= M; ++i)
		V[i] += V[i - 1];

	int len = 1;
	LIS[1] = V[1];
	for (int i = 2; i <= M; ++i) {
		int pos = 0;
		for (int j = fastLog2(len); j >= 0; --j) {
			if ((pos | (1 << j)) <= len && LIS[pos | (1 << j)] <= V[i]) {
				pos |= 1 << j;
			}
		}
		LIS[++pos] = V[i];
		if (pos > len)
			len = pos;
	}

	int answer = len;

	reverse(V + 1, V + M + 1);
	len = 1;
	LIS[1] = V[1];
	for (int i = 2; i <= M; ++i) {
		int pos = 0;
		for (int j = fastLog2(len); j >= 0; --j) {
			if ((pos | (1 << j)) <= len && LIS[pos | (1 << j)] <= V[i]) {
				pos |= 1 << j;
			}
		}
		LIS[++pos] = V[i];
		if (pos > len)
			len = pos;
	}

	answer = max(answer, len);
	cout << answer << '\n';

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int NMAX = 100010;

int N, M;
int V[NMAX], LIS[NMAX], DP[NMAX];

int fastLog2(int value) {
	int answer = 0;
	for (int i = 4; i >= 0; --i) {
		if (value >> (answer | (1 << i))) {
			answer |= 1 << i;
		}
	}
	return answer;
}

int main() {
//	assert(freopen("debug.in", "r", stdin));
//	assert(freopen("debug.out", "w", stdout));

	scanf("%d %d", &N, &M);
	while (N--) {
		int x, y;
		scanf("%d %d", &x, &y);
		++V[x];
		--V[y + 1];
	}

	for (int i = 2; i <= M; ++i)
		V[i] += V[i - 1];

	int len = 1;
	LIS[1] = V[1];
	for (int i = 2; i <= M; ++i) {
		int pos = 0;
		for (int j = fastLog2(len); j >= 0; --j) {
			if ((pos | (1 << j)) <= len && LIS[pos | (1 << j)] <= V[i]) {
				pos |= 1 << j;
			}
		}
		LIS[++pos] = V[i];
		if (pos > len)
			len = pos;
		DP[i] = pos;
	}

	int answer = 0;

	reverse(V + 1, V + M + 1);
	len = 1;
	LIS[1] = V[1];
	for (int i = 2; i <= M; ++i) {
		int pos = 0;
		for (int j = fastLog2(len); j >= 0; --j) {
			if ((pos | (1 << j)) <= len && LIS[pos | (1 << j)] <= V[i]) {
				pos |= 1 << j;
			}
		}
		LIS[++pos] = V[i];
		if (pos > len)
			len = pos;

		answer = max(answer, DP[M - i + 1] + pos - 1);
	}
	answer = max(answer, DP[M]);

	cout << answer << '\n';

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
PI sec[100010];
priority_queue<int,vector<int>,greater<int> > pq;
int cover[100010],bit[100010];
int n;
inline int lowbit(int _x){
	return _x&-_x;
}
inline void modify(int pos,int v){
	pos++;
	for(int i=pos;i<=n+1;i+=lowbit(i))
		bit[i]=max(bit[i],v);
}
inline int query(int pos){
	int res=0;
	pos++;
	for(int i=pos;i>0;i-=lowbit(i))
		res=max(res,bit[i]);
	return res;
}
int main(){
	int m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&sec[i].first,&sec[i].second);
	sort(sec+1,sec+1+n);
	int idx=1;
	int ans=0;
	for(int i=1;i<=m;i++){
		while(idx<=n && sec[idx].first<=i)
			pq.push(sec[idx].second),idx++;
		while(!pq.empty() && pq.top()<i) pq.pop();
		cover[i]=(int)pq.size();
		int cur_lis;
		modify(cover[i],cur_lis=query(cover[i])+1);
		ans=max(ans,cur_lis);
	}
	memset(bit,0,sizeof bit);
	for(int i=m;i>=1;i--){
		int cur_lis;
		modify(cover[i],cur_lis=query(cover[i])+1);
		ans=max(ans,cur_lis);
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
PI sec[100010];
priority_queue<int,vector<int>,greater<int> > pq;
int cover[100010],bit[100010];
int n;
inline int lowbit(int _x){
	return _x&-_x;
}
inline void modify(int pos,int v){
	for(int i=pos;i<=n;i+=lowbit(i))
		bit[i]=max(bit[i],v);
}
inline int query(int pos){
	int res=0;
	for(int i=pos;i>0;i-=lowbit(i))
		res=max(res,bit[i]);
	return res;
}
int main(){
	int m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&sec[i].first,&sec[i].second);
	sort(sec+1,sec+1+n);
	int idx=1;
	int ans=0;
	for(int i=1;i<=m;i++){
		while(idx<=n && sec[idx].first==i)
			pq.push(sec[idx].second),idx++;
		while(!pq.empty() && pq.top()<i) pq.pop();
		cover[i]=(int)pq.size();
		int cur_lis;
		modify(cover[i],cur_lis=query(cover[i])+1);
		ans=max(ans,cur_lis);
	}
	memset(bit,0,sizeof bit);
	for(int i=m;i>=1;i--){
		int cur_lis;
		modify(cover[i],cur_lis=query(cover[i])+1);
		ans=max(ans,cur_lis);
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
PI sec[100010];
priority_queue<int,vector<int>,greater<int> > pq;
int cover[100010],bit[100010],lis[100010],lis2[100010];
int n;
inline int lowbit(int _x){
	return _x&-_x;
}
inline void modify(int pos,int v){
	for(int i=pos+1;i<=n+1;i+=lowbit(i))
		bit[i]=max(bit[i],v);
}
inline int query(int pos){
	int res=0;
	for(int i=pos+1;i>0;i-=lowbit(i))
		res=max(res,bit[i]);
	return res;
}
int main(){
	int m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&sec[i].first,&sec[i].second);
	sort(sec+1,sec+1+n);
	int idx=1;
	int ans=0;
	for(int i=1;i<=m;i++){
		while(idx<=n && sec[idx].first<=i)
			pq.push(sec[idx].second),idx++;
		while(!pq.empty() && pq.top()<i) pq.pop();
		cover[i]=(int)pq.size();
		int cur_lis;
		modify(cover[i],cur_lis=query(cover[i])+1);
		lis[i]=cur_lis;
	}
	memset(bit,0,sizeof bit);
	for(int i=m;i>=1;i--){
		int cur_lis;
		modify(cover[i],cur_lis=query(cover[i])+1);
		lis2[i]=cur_lis;
		ans=max(ans,lis[i]+lis2[i]-1);
	}
	printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 1e5 + 5;
const int INF = 1e8;

int cnt[N], dp[N][2], e[N];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0, l, r; i < n; ++i)
	{
		scanf("%d%d", &l, &r);
		--l;
		++cnt[l];
		--cnt[r];
	}
	for (int i = 1; i <= m; ++i)
		cnt[i] += cnt[i - 1];

	for (int i = 0; i <= m + 1; ++i)
		e[i] = INF;
	e[0] = 0;
	int pos = dp[0][0] = 0;
	for (int i = 0; i < m; ++i)
	{
		int x = upper_bound(e, e + m + 1, cnt[i]) -  e;
		e[x] = cnt[i];
		while(e[pos + 1] < INF)
			++pos;
		dp[i + 1][0] = pos;
	}
	for (int i = 0; i <= m + 1; ++i)
		e[i] = INF;
	e[0] = 0;
	pos = dp[m][1] = 0;
	for (int i = m - 1; i >= 0; --i)
	{
		int x = upper_bound(e, e + m + 1, cnt[i]) -  e;
		e[x] = cnt[i];
		while(e[pos + 1] < INF)
			++pos;
		dp[i][1] = pos;
	}

	int ans = 0;
	for (int i = 0; i <= m; ++i)
		ans = max(ans, dp[i][0] + dp[i][1]);

	printf("%d", ans);

}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10;

int n,m,ans,A[maxn],B[maxn];
int32_t main(){
    scanf("%d%d",&n,&m);
    if(m==1 || n==0){
	printf("%d\n",m-1);
	return 0;
    }
    rep(i,0,n){
	int l,r;
	scanf("%d%d",&l,&r);
	l--;
	A[l]++;
	A[r]--;
    }
    int mx=A[0];
    rep(i,1,m){
	A[i]+=A[i-1];
	mx=max(A[i],mx);
    }
    int mn=maxn+1,plus=1,mu=0;

    rep(i,0,m){
	B[i]=(A[i]==mx)?1:-1;
	if(i) B[i]+=B[i-1];
	if(A[i]==mx){
	    plus=max(plus,B[i]-mn);
	    mn=min(mn,B[i]-1);
	    mu++;
	}
    }
    printf("%d\n",m-mu+plus);
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10,inf=1e9+10;

int n,m,A[maxn],pref[maxn],suff[maxn],lis[maxn];

int32_t main(){
    scanf("%d%d",&n,&m);
    rep(i,0,n){
	int l,r;
	scanf("%d%d",&l,&r);
	l--;
	A[l]++;
	A[r]--;
    }
    rep(i,1,m){
	A[i]+=A[i-1];
    }
    fill(lis,lis+maxn,inf);
    for(int i=0;i<m;i++){
	int pos=upper_bound(lis,lis+maxn,A[i])-lis;
	pref[i]=pos;
	lis[pos]=A[i];
    }
    fill(lis,lis+maxn,inf);
    for(int i=m-1;i>=0;i--){
	int pos=upper_bound(lis,lis+maxn,A[i])-lis;
	suff[i]=pos;
	lis[pos]=A[i];
    }
    int ans=0;
    rep(i,0,m){
	ans=max(ans,pref[i]+suff[i]+1);
    }
    printf("%d\n",ans);
}


#include <bits/stdc++.h>
using std::cin;
using std::cout;
#define ll long long
#define ull unsigned long long
#define eps 1e-12

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define dep(i,x,y) for(int i=(x);i>(y);--i)
#define qry(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();++it)
#define count_intbit(x) __builtin_popcount(x)

#define tpl template
tpl<class _Tp>inline _Tp abs(const _Tp &x){return x<0?-x:x;}
tpl<class _Tp>inline _Tp max(const _Tp &a,const _Tp &b){return a>b?a:b;}
tpl<class _Tp>inline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
tpl<class _Tp>inline void inc(_Tp &a,const _Tp &b){if(a<b)a=b;}
tpl<class _Tp>inline void dec(_Tp &a,const _Tp &b){if(a>b)a=b;}
tpl<class _Tp>inline void swp(_Tp &a,_Tp &b){_Tp c=a;a=b;b=c;}
tpl<class _Tp>inline bool operator ==(const _Tp &A,const _Tp &B){return !memcmp(&A,&B,sizeof(_Tp));}
#undef tpl

#define N 100005

int A[N],f[N],g[N],l[N],n,m,x,y,ans;

int main(){
	cin>>m>>n;
	rep(i,0,m){scanf("%d%d",&x,&y);++A[x];--A[y+1];}
	for(int i=1;i<=n;++i)A[i]+=A[i-1];
	for(int i=1,*t=l;i<=n;++i){
		int *j=std::upper_bound(l,t,A[i]);
		f[i]=j-l+1; *j=A[i]; inc(t,j+1);
	}
	for(int i=n,*t=l;i>=1;--i){
		int *j=std::upper_bound(l,t,A[i]);
		g[i]=j-l+1; *j=A[i]; inc(t,j+1);
	}
	for(int i=1;i<=n;++i)inc(ans,f[i]+g[i]-1);
	return !printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
#define pb push_back
#define mp make_pair
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define N 100010
#define INF 2*1e6
int start[N], val[N], end[N], tree[4*N], dp1[N], dp2[N];
vector<pair<int,int> > pts;
void update(int low,int high,int ind,int val, int node){
	if(low == high){
		tree[node] = max(val,tree[node]);
		return;
	}
	int mid = (low + high)/2;
	if(ind <= mid)
		update(low,mid,ind,val,2*node);
	else
		update(mid+1,high,ind,val,2*node+1);
	tree[node] = max(tree[2*node], tree[2*node+1]);
}
int query(int low,int high,int begin,int end,int node){
	if(low > end || high < begin || begin > end)
		return -1*INF;
	if(low >= begin && high <= end)
		return tree[node];
	int mid = (low + high)/2;
	return max(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		start[x]++;
		end[y]++;
	}
	int cur = 0;
	for(int i=1;i<=m;i++){
		cur += start[i];
		val[i] = cur;
		cur -= end[i];
	}
	int maxi = 0;
	for(int i=1;i<=m;i++){
		dp1[i] = max(query(0,m,1,val[i],1),0) + 1;
		update(0,m,val[i],dp1[i],1);
		maxi = max(maxi, dp1[i]);
	}
	memset(tree,0,sizeof(tree));
	for(int i=1;i<=m;i++){
		dp2[i] = max(query(0,m,val[i],m,1),0) + 1;
		update(0,m,val[i],dp2[i],1);
		maxi = max(maxi,dp2[i]);
	}
	cout<<maxi<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
#define pb push_back
#define mp make_pair
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define N 100010
#define INF 2*1e6
int start[N], val[N], endi[N], tree[4*N], dp1[N], dp2[N];
vector<pair<int,int> > pts;
void update(int low,int high,int ind,int val, int node){
	if(low == high){
		tree[node] = max(val,tree[node]);
		return;
	}
	int mid = (low + high)/2;
	if(ind <= mid)
		update(low,mid,ind,val,2*node);
	else
		update(mid+1,high,ind,val,2*node+1);
	tree[node] = max(tree[2*node], tree[2*node+1]);
}
int query(int low,int high,int begin,int end,int node){
	if(low > end || high < begin || begin > end)
		return -1*INF;
	if(low >= begin && high <= end)
		return tree[node];
	int mid = (low + high)/2;
	return max(query(low,mid,begin,end,2*node),query(mid+1,high,begin,end,2*node+1));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		start[x]++;
		endi[y]++;
	}
	int cur = 0;
	for(int i=1;i<=m;i++){
		cur += start[i];
		val[i] = cur;
		cur -= endi[i];
	}
	int maxi = 0;
	dp1[0] = 0;
	dp2[m+1] = 0;
	for(int i=1;i<=m;i++){
		dp1[i] = max(query(0,m,1,val[i],1),0) + 1;
		update(0,m,val[i],dp1[i],1);
	}
	memset(tree,0,sizeof(tree));
	for(int i=m;i>=1;i--){
		dp2[i] = max(query(0,m,1,val[i],1),0) + 1;
		update(0,m,val[i],dp2[i],1);
	}
	for(int i=1;i<=m;i++){
		maxi = max(maxi,dp1[i] + dp2[i] - 1);
	}
	cout<<maxi<<'\n';
}