#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
 
#define mp make_pair
#define fi first
#define se second
 
//mt19937 rng(time(NULL)); //int
//mt19937_64 rng(time(NULL)); //Long Long
//shuffle(a.begin(),a.end(),rng); //shuffle
//rng(); //random

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n,m;
	cin>>n>>m;
	vector<int> tem[m+10];
	
	for(int i=1; i<=n; i++){
		int x,y;
		cin>>x>>y;
		x=max(x,1);
		tem[x].push_back(y);
	}
	priority_queue<int> pq;
	int cnt=0;
	for(int i=1; i<=m; i++){
		for(int j=0; j<tem[i].size(); j++) pq.push(-tem[i][j]);
		if(!pq.empty()) pq.pop();
		while(!pq.empty()){
			int x=-pq.top();
			if(x>i) break;
			cnt++;
			pq.pop();
		}
	}
	cout<<cnt<<endl;
}