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>
using namespace std;

class FordFullkerson{
    using type=int;
    const int INF=1e9;
    struct Edge{
        int to;
        type cap;
        int rev;
        Edge(int _t,type _c,int _r):to(_t),cap(_c),rev(_r){}
    };

    using Graph=vector<vector<Edge>>;
    int V;
    Graph G;

    vector<bool> usd;

    type dfs(int v,int t,type f){
        if(v==t) return f;
        usd[v]=true;
        for(auto &e:G[v]){
            if(!usd[e.to] && e.cap>0){
                auto d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    public:
    FordFullkerson(int _v) : V(_v),G(_v),usd(_v){}
    void add(int from,int to,type cap){
        G[from].push_back(Edge{to,cap,(int)(G[to].size())});
        G[to].push_back(Edge{from,0,(int)(G[from].size())-1});
    }

    type maxFlow(int s,int t){
        type ret=0;
        while(true){
            for(int i=0;i<(int)(G.size());i++){
                usd[i]=false;
            }
            type f=dfs(s,t,INF);
            if(f==0) return ret;
            ret+=f;
        }
    }

};

using Graph=vector<vector<int>>;

void dfs(int v,Graph& g,vector<int>& used){
    if(used[v]) return;
    used[v]=true;
    for(auto to:g[v]) dfs(to,g,used);
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> x(m),y(m);
    for(int i=0;i<m;i++) cin>>x[i]>>y[i],x[i]--,y[i]--;
    vector<vector<int>> xi(n);
    vector<vector<int>> yi(n);
    for(int i=0;i<m;i++) xi[x[i]].push_back(i);
    for(int i=0;i<m;i++) yi[y[i]].push_back(i);

    // partMax

    Graph g(m);
    for(int i=0;i<m;i++){
        for(auto to:xi[x[i]]){
            g[i].push_back(to);
        }
        for(auto to:yi[y[i]]){
            g[i].push_back(to);
        }
    }

    vector<int> used(m);
    int cnt=0;
    for(int i=0;i<m;i++){
        if(!used[i]){
            dfs(i,g,used);
            cnt++;
        }
    }
    int ansMax=m-cnt;

    // partMin
    int z=0;
    FordFullkerson flow(2*n+2);
    int S=2*n;
    int T=2*n+1;

    for(int i=0;i<n;i++){
        flow.add(S,i,1);
    }
    for(int i=0;i<n;i++){
        flow.add(n+i,T,1);
    }
    for(int i=0;i<m;i++){
        flow.add(x[i],n+y[i],1);
    }

    int ret=flow.maxFlow(S,T);
    int ansMin=m-ret;

    cout<<ansMin<<" "<<ansMax<<endl;

    return 0;
}