#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e18)

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;
	vector<M> val;
	F f;
	M e;

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = 0; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	M query(int l, int r){
		M L = e, R = e;
		for(l += size, r += size; l < r; l /= 2, r /= 2){
			if(l & 1) L = f(L, val[l++]);
			if(r & 1) R = f(val[--r], R);
		}
		return f(L, R);
	}
};

int mini(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, L, i, j;
	scanf("%lld%lld", &N, &L);
	vector<int> l(N), r(N);
	vector<int> event(0);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &l[i], &r[i]);
		event.push_back(l[i]);
		event.push_back(r[i]);
	}
	sort(event.begin(), event.end());
/*	for(i = 1, j = 1; j < 2 * N; j++){
		if(event[j] != event[j - 1]){
			event[i] = event[j];
			i++;
		}
	}
	event.erase(event.begin() + i, event.end());
*/	L = 0;
	for(i = 0; i < N; i++){
		l[i] = lower_bound(event.begin(), event.end(), l[i]) - event.begin();
		r[i] = lower_bound(event.begin(), event.end(), r[i]) - event.begin();
		L = max(L, r[i]);
	}
/*	printf("L = %lld\n", L);
	for(i = 0; i < N; i++){
		printf("(%lld, %lld)\n", l[i], r[i]);
	}
*/	vector<vector<int>> corl(L + 1, vector<int>(0));
	for(i = 0; i < N; i++){
		corl[r[i]].push_back(l[i]);
	}
	vector<int> data(L + 1, inf);
//	data[0] = 0;
	segment_tree<int> dp(L + 1, data, mini, inf);
	dp.update(0, 0);
//	printf("dp[0] = %lld\n", dp.query(0, 1));
	for(i = 1; i <= L; i++){
//		printf("i = %lld\n", i);
		int now = inf;
		for(j = 0; j < corl[i].size(); j++){
//			printf("corl[i][%lld]\n", corl[i][j]);
			now = min(now, dp.query(corl[i][j], i) + 1);
		}
//		printf("test3\n");
		dp.update(i, now);
//		printf("%lld\n", dp.query(i, i + 1));
	}
//	printf("test5\n");
	printf("%lld ", dp.query(L, L + 1));

	vector<int> A(L + 1, 0);
	for(i = 0; i < N; i++){
		A[l[i]]++;
		A[r[i]]--;
	}
	int minA = A[0];
	for(i = 1; i < L; i++){
		A[i] += A[i - 1];
		minA = min(minA, A[i]);
	}
/*	for(i = 0; i <= L; i++){
		printf("A[%lld] = %lld\n", i, A[i]);
	}
*/	printf("%lld\n", N - minA + 1);
	return 0;
}
