#include<bits/stdc++.h>
#define LL long long
#define N 200005
#define MOD 1000000007
#define bas 8741
#define pli pair<LL, int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int n, m, maxday, ans1, ans2, x;
struct node {
    int st, ed, id;
}a[N];
priority_queue<int, vector<int>, greater<int> > q;
const int Maxn = 2000 + 10;
const int INF = 0x6fffffff >> 2;

struct edge
{
	int from , to , cap , flow;
};

struct Dinic
{
	int n, m, s, t;
	vector<edge> edges;
	vector<int> f[Maxn];
	bool vis[Maxn];
	int d[Maxn];
	int cur[Maxn];

	void AddEdge(int from, int to, int cap)
	{
		edges.push_back((edge){from, to, cap, 0});
		edges.push_back((edge){to, from, 0, 0});
		m = edges.size();
		f[from].push_back(m - 2);
		f[to].push_back(m - 1);
	}

	bool BFS()
	{
		memset(vis, 0, sizeof(vis));
		queue<int> q;
		q.push(s);
		d[s] = 0;
		vis[s] = 1;
		while (!q.empty())
		{
			int x = q.front();
			q.pop();
			for (int i = 0; i < f[x].size(); ++i)
			{
				edge &e = edges[f[x][i]];
				//cout<<"to="<<e.to<<"from="<<e.from<<' '<<e.flow<<' '<<e.cap<<' '<<vis[e.to]<<endl;
				if (!vis[e.to] && e.flow < e.cap) //Ö»¿¼ÂÇ²ÐÁôÍøÂçÖÐµÄ»¡
				{
					vis[e.to] = 1;
					d[e.to] = d[x] + 1;//²ã´ÎÍ¼
					q.push(e.to);
				}
			}
		}
		return vis[t];//ÄÜ·ñµ½»ãµã£¬²»ÄÜ¾Í½áÊø
	}
	int DFS(int x, int a)//xÎªµ±Ç°½Úµã£¬aÎªµ±Ç°×îÐ¡²ÐÁ¿
	{
		if (x == t || a == 0)
			return a;
		int flow = 0, r;

		for (int& i = cur[x]; i < f[x].size(); ++i)
		{
			edge& e = edges[f[x][i]];
			if (d[x] + 1 == d[e.to] && (r = DFS(e.to , min(a, e.cap - e.flow))) > 0)
			{
				e.flow += r;
				edges[f[x][i] ^ 1].flow -= r;
				flow += r;//ÀÛ¼ÓÁ÷Á¿
				a -= r;
				if (a == 0)
					break;
			}
		}
		return flow;
	}
	int MaxFlow(int s,int t)
	{
		this->s = s;
		this->t = t;
		int flow = 0;
		while (BFS())
		{
			memset(cur, 0, sizeof(cur));
			flow += DFS(s, INF);
		}
		return flow;
	}
}G;
bool cmp(const node &lhs, const node &rhs) {
    return lhs.st < rhs.st;
}
int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", &a[i].st, &a[i].ed);
        maxday = max(maxday, a[i].ed);
        if(i <= m) a[i].id = 0;
        else a[i].id = 1;
    }
    G.s = n + 2 * maxday + 1, G.t = G.s + 1;
    for(int i = 1; i <= m; ++i) {
        G.AddEdge(G.s, i, 1);
        for(int j = a[i].st; j <= a[i].ed; ++j) {
            G.AddEdge(i, n + j, 1);
        }
    }
    for(int i = m + 1; i <= n; ++i) {
        G.AddEdge(i, G.t, 1);
        for(int j = a[i].st; j <= a[i].ed; ++j) {
            G.AddEdge(n + maxday + j, i, 1);
        }
    }
    for(int i = 1; i <= maxday; ++i) G.AddEdge(n + i, n + maxday + i, 1);
    ans2 = G.MaxFlow(G.s, G.t);
    sort(a + 1, a + n + 1, cmp);
    int now = 1;
    for(int i = 1; i <= maxday; ++i) {
        while(a[now].st == i && now <= n) {
            q.push(a[now].ed);
            now++;
        }

        if(!q.empty()) {
            while(!q.empty()) {
                if(q.top() < i) q.pop();
                else break;
            }
            if(!q.empty()) {
                x = q.top();
                q.pop();
                ans1++;
            }
        }
    }
    printf("%d\n%d\n", ans1, ans2);
    return 0;
}



Measured memory_bytes: 5360