#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<cstdlib>
#include<ctime>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;
 
inline int read() {
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;	
} 
 
const int N = 2e5+5, NM = 8e5+7, M = 1.6e7+5, inf = 1e9+7;
struct edge{ int to, nxt, v; } e[M];
int head[NM], cnt = 1, tot, S, T;
inline void add(int x,int y,int v) { 
	e[++cnt].to = y, e[cnt].v = v, e[cnt].nxt = head[x], head[x] = cnt;
	e[++cnt].to = x, e[cnt].v = 0, e[cnt].nxt = head[y], head[y] = cnt;
}
int id[N<<2], pos[N];
#define lc k<<1
#define rc k<<1|1
inline void build(int l,int r,int k) { 
	id[k] = ++tot;
	if( l == r ) { pos[l] = id[k]; return; }
	int mid = (l + r) >> 1;
	build(l,mid,lc), build(mid+1,r,rc), add(id[k],id[lc],inf), add(id[k],id[rc],inf);
}
 
int ql, qr, now;
inline void upd(int l,int r,int k) { 
	if( ql <= l && r <= qr ) { add(now,id[k],1); return; }
	int mid = (l + r) >> 1;
	if( ql <= mid ) upd(l,mid,lc);
	if( qr > mid ) upd(mid+1,r,rc);
}
 
int h[NM], q[NM];
#define ez(i,j) for(register int i = head[j]; i; i=e[i].nxt)
#define to e[i].to
inline bool bfs() { 
	int l = 0, r = 1, x; 
	rep(i,S,T) h[i] = 0; h[q[r]=S]=1;
	while( l < r ) { 
		x = q[++l];
		ez(i,x) if( !h[to] && e[i].v ) h[q[++r]=to] = h[x] + 1;
	} return h[T];
}
 
inline int dfs(int x,int f) { 
	if( x == T ) return f;
	int used = 0, w;
	ez(i,x) if( h[to] == h[x] + 1 && e[i].v ) { 
		w = dfs(to,min(f-used,e[i].v));
		used += w, e[i].v -= w, e[i^1].v += w;
		if( f == used ) return f;
	}
	return h[x] = -1, used;
}
 
int main() {
	int n = read(), m = read(); tot = n;
	build(1,m,1); T = ++tot;
	rep(i,1,m) add(pos[i],T,1);
	rep(i,1,n) { 
		add(S,now = i,1);
		ql = 1, qr = read();
		if( ql <= qr ) upd(1,m,1);
		ql = read(), qr = m;
		if( ql <= qr ) upd(1,m,1);
	}
	int ans = 0;
	while( bfs() ) ans += dfs(S,inf);
	cout<<n - ans<<endl;
    return 0;
} 