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>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 1005

struct Info{

	int x,y;
};

int N,M;
Info info[SIZE];

int V;
vector<int> G[2*SIZE];
map<int,int> X,Y;
int match[2*SIZE];
bool used[2*SIZE];

void add_edge(int from,int to){
	G[from].push_back(to);
	G[to].push_back(from);
}


int dfs(int node_id){
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
		if((pair_id < 0)||
				(used[pair_id] == false && dfs(pair_id) == true)){

			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;
			return true;
		}
	}
	return false;
}


int bipartie_matching(){
	int ret = 0;
	for(int i = 0; i < V; i++)match[i] = -1;
	for(int node_id = 0; node_id < V; node_id++){
		if(match[node_id] < 0){
			for(int i = 0; i < V; i++)used[i] = false;
			if(dfs(node_id)){
				ret++;
			}
		}
	}
	return ret;
}

int boss[SIZE],height[SIZE];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int isSame(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[boss_x] > height[boss_y]){

		boss[boss_y] = boss_x;

	}else if(height[boss_x] < height[boss_y]){

		boss[boss_x] = boss_y;

	}else{ //height[boss_x] == height[boss_y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}

int main(){

	scanf("%d %d",&N,&M);

	int num_x = 0,num_y = 0;

	for(int i = 0; i < M; i++){

		scanf("%d %d",&info[i].x,&info[i].y);
		info[i].x--;
		info[i].y--;

		auto at = X.find(info[i].x);

		if(at == X.end()){

			X[info[i].x] = num_x;
			num_x++;
		}

		at = Y.find(info[i].y);

		if(at == Y.end()){


			Y[info[i].y] = num_y;
			num_y++;
		}
	}

	V = num_x+num_y;

	for(int i = 0; i < M; i++){

		add_edge(X[info[i].x],num_x+Y[info[i].y]);
	}

	int minimum = M-bipartie_matching(); //最も多くルークを残したので、キャプチャする数は最小


	for(int i = 0; i < M; i++){

		boss[i] = i;
		height[i] = 0;
	}

	for(int i = 0; i < M-1; i++){
		for(int k = i+1; k < M; k++){
			if(info[i].x != info[k].x && info[i].y != info[k].y)continue;

			unite(i,k);
		}
	}

	int num_group = 0;
	for(int i = 0; i < M; i++){
		if(i == get_boss(i)){

			num_group++;
		}
	}

	int maximum = M-num_group; //残るルークを最小化したので、キャプチャする数は最大

	printf("%d %d\n",minimum,maximum);

	return 0;
}