#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define S 0
#define T 363005
struct Edge{
	int to, f, next;
}e[2100006];
int cur[T + 1], head[T + 1], vis[T + 1], dis[T + 1], q[T + 1], id[262206], vn, en, pos, lbd, rbd;
int BFS(){
	register int i, u, v, qh, qt;
	memset(dis, 0, sizeof(dis));
	q[qh = qt = 0] = T;
	dis[T] = 1;//vis[T] = dis[T] = 1;
	while (qh <= qt) {
		u = q[qh];
		++qh;
		for (i = head[u]; i; i = e[i].next) {
			if (e[i ^ 1].f && dis[v = e[i].to] == 0) {
				q[++qt] = v;
				dis[v] = dis[u] + 1;
			}
		}
	}
	return dis[S];
}
int Dinic(register int u, register int mf){
	if (u == T) return mf;
	register int to, nowf = mf, tmp;
	for (register int &i = cur[u]; i; i = e[i].next) {
		if (e[i].f && dis[to = e[i].to] + 1 == dis[u]) {
			tmp = Dinic(to, dmin(nowf, e[i].f));
			if (tmp) {
				nowf -= tmp;
				e[i].f -= tmp;
				e[i ^ 1].f += tmp;
				if (nowf == 0) return mf;
			}
		}
	}
	return mf - nowf;
}
int MaxFlow(){
	register int FL = 0;
	while (BFS()) {
		memcpy(cur, head, sizeof(head));
		FL += Dinic(S, 0x3f3f3f3f);
	}
	return FL;
}
inline void AddEdge(register int u, register int v, register int f){
	e[++en] = (Edge){v, f, head[u]};
	head[u] = en;
	e[++en] = (Edge){u, 0, head[v]};
	head[v] = en;
	return ;
}
void Build(register int o, register int l, register int r){
	id[o] = ++vn;
	//fprintf(stderr, "%d %d %d %d\n", o, l, r, id[o]);
	if (l == r) {
		AddEdge(id[o], T, 1);
		return ;
	}
	register int o2 = o << 1, mid = l + r >> 1;
	Build(o2, l, mid);
	Build(o2 | 1, mid + 1, r);
	AddEdge(id[o], id[o2], 0x3f3f3f3f);
	AddEdge(id[o], id[o2 | 1], 0x3f3f3f3f);
	return ;
}
void Cover(register int o, register int l, register int r){
	if (lbd <= l && r <= rbd) {
		AddEdge(pos, id[o], 1);
		//fprintf(stderr, "[%d %d %d] [%d %d %d] %d\n", pos, lbd, rbd, o, l, r, id[o]);
		return ;
	}
	register int o2 = o << 1, mid = l + r >> 1;
	if (lbd <= mid) Cover(o2, l, mid);
	if (mid < rbd) Cover(o2 | 1, mid + 1, r);
	return ;
}
int x[100008];
int main(){
	register int n, m, i, j, l, r, ans;
	!scanf("%d %d", &n, &m);
	en = 1;
	for (i = 1; i <= n; ++i) AddEdge(S, i, 1);
	vn = n;
	Build(1, 1, m);
	for (i = 1; i <= n; ++i) {
		!scanf("%d %d", &l, &r);
		pos = i;
		if (l) {
			lbd = 1, rbd = l;
			Cover(1, 1, m);
		}
		//fprintf(stderr, "\n");
		if (r <= m) {
			lbd = r, rbd = m;
			Cover(1, 1, m);
		}
	}
	//fprintf(stderr, "[%d]\n", en);
	printf("%d\n", n - MaxFlow());
	return 0;
}