#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>

using namespace std;
typedef vector<int>::iterator viter;
const int N = 400010;
int _w;

int n, m, ans;
vector<int> right[N];
priority_queue<int, vector<int>, greater<int> > pq;

int main() {
	_w = scanf( "%d%d", &n, &m );
	for( int i = 0; i < n; ++i ) {
		int l, r;
		_w = scanf( "%d%d", &l, &r );
		l += m, swap(l, r);
		if( l <= r ) right[l].push_back(r);
	}
	for( int i = 1; i <= m+m; ++i ) {
		for( viter it = right[i].begin(); it != right[i].end(); ++it )
			pq.push(*it);
		while( !pq.empty() && pq.top() < i )
			pq.pop();
		if( !pq.empty() )
			++ans, pq.pop();
	}
	ans = min(ans, m);
	printf( "%d\n", n-ans );
	return 0;
}
