#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>
#pragma comment(linker, "/STACK:1024000000,1024000000") 
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define X first
#define Y second
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> tree_set;
typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update> tree_map;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> heap;
typedef cc_hash_table<int,int> cc_hashmap;
typedef cc_hash_table<int,null_type> cc_hashset;
typedef gp_hash_table<int,int> gp_hashmap;
typedef gp_hash_table<int,null_type> gp_hashset;
heap q1,q2;
int n,m;
pair<int,int> p[200005];
inline bool cmp(pair<int,int> &x,pair<int,int> &y){
	if(x.X!=y.X)return x.X<y.X;
	return x.Y>y.Y;
}
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-'0';
		c=getchar();
	}
	return s*t;	
} 
int main(){
	n=read();
	m=read();
	for(int i=0;i<n;i++){
		p[i].X=read();
		p[i].Y=read();
	}
	sort(p,p+n,cmp);
	int ans=n;
	for(int i=0;i<n;i++){
		if(p[i].X==q1.size()){
			q1.push(p[i].Y);
			q2.push(q1.top());
			q1.pop();
		}
		else{
			q1.push(p[i].Y);
			ans--;
		}
	}
	for(int i=q1.size()+1;!q2.empty() && i<=m;i++){
		if(q2.top()<=i){
			q2.pop();
			ans--;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14336