#include <iostream> 
#include <cstdio>
#include <algorithm>

using namespace std;

#define For(i , a , b) for (int i = a , _b = b ; i <= _b ; ++i)
#define Ford(i , a  ,b) for (int i = a , _b = b : i >= _b ; --i)
#define Rep(i , n) for (int i = 0 , _n = n ; i < _n ; ++i)
#define sz(A) ((int)A.size())
#define LL(x) (x << 1)
#define RR(x) ((x << 1) | 1)

typedef pair<int , int> pt;
const int maxn = 300000  + 123;
int n, m;
pt a[maxn];

#define fi first
#define se second

void ReadData() {
    cin >> n >> m;
    For(i,1,n) cin >> a[i].first >> a[i].second;
}

bool cmp(pt a, pt b) {
    if (a.second == b.second) return a.first > b.first
    return a.second > b.second;
}

class segmentTree{
public:
    int l[maxn * 4], h[maxn * 4];
    int it[maxn * 4];
    int lazy[maxn * 4];

    void buildTree(const int x, const int lo, const int hi) {
        l[x] = lo; h[x] = hi;
        lazy[x] = 0;
        if (lo == hi) {
            it[x] = lo;
        } else {
            int mid = (lo + hi) >> 1;
            buildTree(LL(x), lo, mid);
            buildTree(RR(x),mid + 1, hi);
            it[x] = min(it[LL(x)], it[RR(x)]);
        }
    } 

    void add(const int x, const int val) {
        it[x] += val;
        lazy[x] += val;
    }

    void pushDown(const int x) {
        if (lazy[x] != 0) {
            add(LL(x), lazy[x]);
            add(RR(x), lazy[x]);
            lazy[x] = 0;
        }
    } 

    void update(const int x, const int u, const int v, const int val) {
        if (l[x] > v || h[x] < u) return;
        if (u <= l[x] && h[x] <= v) {
            add(x,val);
            return;
        }
        pushDown(x);
        update(LL(x),u,v,val);
        update(RR(x),u,v,val);
        it[x] = min(it[LL(x)], it[RR(x)]);
    }
} tree;

void Process() {
    tree.buildTree(1,0,200000);

    int minVal = maxn;
    sort(a + 1, a + 1 + n, cmp);
    For(i,1,n) {
        tree.update(1, a[i].first, 200000, -1);
        minVal = min(minVal, tree.it[1] + m - a[i].second + 1);
    }

    if (minVal >= 0) minVal = 0;
    cout << -minVal << endl; 
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
   // freopen("input.inp" , "r", stdin);
    ReadData();
    Process();

	return 0;

}			