#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int MAX_N = 2e5 + 6;

vector<int> v[MAX_N];

int main() {
	int n,m;
	scanf("%d %d",&n,&m);
	for (int i=1;n>=i;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		v[x].push_back(y);
	}
	for (int i=0;m+1>=i;i++) {
		sort(v[i].begin(),v[i].end());
	}
	priority_queue<int,vector<int>,greater<int> > pq;
	int nxt=0;
	for (int i=0;m>=i;i++) {
		if (i==0) {
			for (int j:v[i]) {
				pq.push(j);
			}
		}
		else {
			if (v[i].size() == 0) {
				if (!pq.empty() && pq.top()<=i) pq.pop();
				else {
					if (nxt < i) nxt=i;
					while (v[nxt].size() == 0 && nxt<=m+1) nxt++;
					if (v[nxt].size() == 0) continue;
					else v[nxt].pop_back();
				}
			}
			else {
				for (int j=0;v[i].size()-1>j;j++) {
					pq.push(v[i][j]);
				}
			}
		}
	}
	printf("%d\n",pq.size());
}
