Problem: Problem Statement

"Rooks Game" is a single-player game and uses a chessboard which has $N \times N$ grid and $M$ rook pieces.

A rook moves through any number of unoccupied squares horizontally or vertically. When a rook can attack another rook, it can capture the rook and move to the square which was occupied. Note that, in Rooks Game, we don't distinguish between white and black, in other words, every rook can capture any of other rooks.

<image>

Initially, there are $M$ rooks on the board. In each move, a rook captures another rook. The player repeats captures until any rook cannot be captured. There are two types of goal of this game. One is to minimize the number of captured rooks, and the other is to maximize it.

In this problem, you are requested to calculate the minimum and maximum values of the number of captured rooks.

* * *

Input

The input consists of a single test case in the format below.

> $N$ $M$ $x_{1}$ $y_{1}$ $\vdots$ $x_{M}$ $y_{M}$

The first line contains two integers $N$ and $M$ which are the size of the chessboard and the number of rooks, respectively ($1 \le N, M \le 1000$). Each of the following $M$ lines gives the position of each rook. The $i$-th line with $x_{i}$ and $y_{i}$ means that the $i$-th rook is in the $x_{i}$-th column and $y_{i}$-th row ($1 \le x_{i}, y_{i} \le N$). You can assume any two rooks are not in the same place.

Output

Output the minimum and maximum values of the number of captured rooks separated by a single space.

Examples

Input| Output
---|---


8 3
1 1
1 8
8 8


|


1 2



8 4
1 1
1 8
8 8
8 1


|


2 3



5 5
1 1
2 2
3 3
4 4
5 5


|


0 0



100 1
100 100


|


0 0



10 12
1 2
1 4
1 6
3 6
5 6
10 7
8 7
6 7
4 7
2 7
7 3
9 5


|


7 8






Example

Input




Output

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

const int MAXN = 1e3 + 10, INF = 1e9;

int n, m;
int id[MAXN][MAXN], fa[MAXN];

struct NetWork {
	static const int MAXM = MAXN * MAXN + MAXN * 10;
	int B, E, sum, N,  MaxFlow, MinCost;
	int last[MAXN << 1], vis[MAXN << 1], cur[MAXN << 1], dis[MAXN << 1];
	struct Edge { int link, to, flow, cost; } edge[MAXM << 1];
	inline void Init(int _, int __, int ___) {
		B = _, E = __, N = ___, sum = -1;
		std::fill(last, last + N + 1, -1);
	}
	inline void Add(int u, int v, int f, int c) { edge[++sum] = (Edge) { v, last[u], f, c }, last[u] = sum; }
	inline void AddEdge(int u, int v, int f, int c) { Add(u, v, f, c), Add(v, u, 0, -c); }
	inline int SPFA() {
		std::queue <int> Q;
		std::fill(dis, dis + N + 1, INF), dis[B] = 0, Q.push(B);
		while (!Q.empty()) {
			int x = Q.front(); Q.pop(); vis[x] = 0;
			for (int i = last[x]; ~i; i = edge[i].to) {
				int y = edge[i].link, c = edge[i].cost;
				if (dis[y] > dis[x] + c && edge[i].flow) {
					dis[y] = dis[x] + c;
					if (!vis[y]) vis[y] = 1, Q.push(y);
				}
			}
		}
		return dis[E] != INF;
	}
	int Dfs(int x, int dist) {
		int flown = 0, f;
		if (x == E || !dist) return dist; vis[x] = 1;
		for (int &i = cur[x]; ~i; i = edge[i].to) {
			int y = edge[i].link;
			if (!vis[y] && dis[y] - dis[x] == edge[i].cost && ((f = Dfs(y, std::min(dist, edge[i].flow))) > 0)) {
				edge[i].flow -= f, edge[i ^ 1].flow += f;
				flown += f, dist -= f;
				if (!dist) break;
			}
		}
		vis[x] = 0;
		return flown;
	}
	inline void ZKW() {
		MaxFlow = MinCost = 0;
		while (SPFA()) {
			for (int i = 0; i <= N; ++i) cur[i] = last[i], vis[i] = 0;
			int d = Dfs(B, INF);
			MaxFlow += d, MinCost += d * dis[E];
		}
	}
} G;
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, x, y; i <= m; ++i) scanf("%d%d", &x, &y), id[x][y] = i;
	for (int i = 1; i <= m; ++i) fa[i] = i;
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = 1, lst = 0; j <= n; ++j) if (id[i][j]) {
			if (lst) {
				int x = find(lst), y = find(id[i][j]);
				if (x != y) fa[y] = x, ++cnt;
			}
			lst = id[i][j];
		}
	for (int j = 1; j <= n; ++j)
		for (int i = 1, lst = 0; i <= n; ++i) if (id[i][j]) {
			if (lst) {
				int x = find(lst), y = find(id[i][j]);
				if (x != y) fa[y] = x, ++cnt;
			}
			lst = id[i][j];
		}
	int S = n * 2 + 1, T = S + 1, N = T;
	G.Init(S, T, N);
	for (int i = 1; i <= n; ++i) G.AddEdge(S, i, 1, 0);
	for (int i = 1; i <= n; ++i) G.AddEdge(i + n, T, 1, 0);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) G.AddEdge(i, j + n, 1, id[i][j] ? 1 : 2);
	G.ZKW();
	printf("%d %d\n", m - (2 * n - G.MinCost), cnt);
	return 0;
}