#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;
int inf = 2e9, mod = 1e9 + 7;
struct SEG{
    int comb = 1, l,r;
    vi st, lazy;
    SEG(int n){
        for(int i = n-1;i;i>>=1) comb <<= 1;
        st.resize(2*comb); lazy.resize(2*comb, 0);
        for(int i=0;i<comb;i++) st[comb + i] = -i;
        for(int i = comb-1;i;--i) st[i] = max(st[i<<1], st[i<<1|1]);
    }
    void push(int cur){
        st[cur] += lazy[cur];
        if(cur < comb) lazy[cur<<1] += lazy[cur], lazy[cur<<1|1] += lazy[cur];
        lazy[cur] = 0;
    }

    void update(int _l, int _r){
        l = _l; r = _r;
        update(1,0,comb - 1);
    }
    inline void update(int cur, int rl, int rr){
        push(cur);
        if(rr < l || rl > r) return;
        if(l <= rl && r >= rr){
            lazy[cur]++;
            push(cur);
            return;
        }
        int mid = (rl+rr)>>1;
        update(cur << 1, rl, mid);
        update(cur << 1 | 1, mid + 1, rr);
        st[cur] = max(st[cur << 1], st[cur << 1]);
    }

    int query(){
        return st[1];
    }

};
int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n, m;
    cin >> n >> m;
    SEG st(m+2);
    ii bnd(-inf, inf);
    vector<ii> p(n);
    for(int i=0;i < n;i++){
        cin >> p[i].x >> p[i].y;
        bnd.x = max(bnd.x, p[i].x);
        bnd.y = min(bnd.y, p[i].y);
    }
    int res = n - min(m ,m - (bnd.y - bnd.x - 1));
    sort(all(p));
    for(auto &e:p){
        st.update(e.y, st.comb - 1);
        res = max(res, -e.x + st.query());
    }
    cout << res << endl;
    return 0;
}
