#include <bits/stdc++.h>
using namespace std;
#define F(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define D(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
int rd() {
	char c; do { c = getchar(); } while (!isdigit(c));
	int x = 0; do { x = x*10+c-'0', c = getchar(); } while (isdigit(c)); return x;
}

const int N = 200005;
const int S = 600000;
const int INF = -1u>>2;

int n, m, ans, tag[S], Mx[S];
struct I {
	int l, r;
	friend int operator < (I a, I b) { return a.r < b.r; }
}it[N];

#define Lc (x << 1)
#define Rc (x << 1 | 1)
#define M (L+R >> 1)
void Pro(int x, int L, int R) {
	Mx[x] = -L;
	if (L != R) {
		Pro(Lc, L, M);
		Pro(Rc, M+1, R);
	}
}
void Dw(int x, int t) { tag[x] += t, Mx[x] += t; }
void CLR(int x) {
	int &t = tag[x];
	if (t) {
		Dw(Lc, t);
		Dw(Rc, t), t = 0;
	}
}
void Mo(int x, int L, int R, int l, int r) {
	if (l <= L && R <= r) return Dw(x, +1), void();
	CLR(x);
	if (l <= M) Mo(Lc, L, M, l, r);
	if (M < r) Mo(Rc, M+1, R, l, r);
	Mx[x] = max(Mx[Lc], Mx[Rc]);
}
int Max(int x, int L, int R, int l, int r) {
	if (l <= L && R <= r) return Mx[x];
	CLR(x);
	int ans = -INF;
	if (l <= M) ans = max(ans, Max(Lc, L, M, l, r));
	if (M < r) ans = max(ans, Max(Rc, M+1, R, l, r));
	return ans;
}

int main() {
	n = rd(), m = rd();
	F(i, 1, n) {
		int l = rd(), r = rd();
		it[i] = (I){l, r};
	}
	sort(it+1, it+n+1);
	Pro(1, 0, m+1);
	
	D(i, n, 1) {
		int l = it[i].l, r = it[i].r;
		Mo(1, 0, m+1, 0, l);
		ans = max(ans, Max(1, 0, m+1, 0, r) - (m-r+1));
	}
	printf("%d\n", ans);
	
	return 0;
}