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 <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

#define SIZE 400000
#define SIZE0 200000
#define INF 1000000000

typedef long long ll;

struct Dinic{

  struct edge{
    int to, cap, rev;
    edge(int a, int b, int c): to(a), cap(b), rev(c){}
  };

  vector<vector<edge>>G;
  vector<int> level, itr;
  int MAX_V;

  Dinic(int max_v): G(max_v), MAX_V(max_v) {}

  int add_edge(int from, int to, int cap) {
    int id = G[from].size();

    G[from].push_back(edge(to, cap, G[to].size()));
    G[to].push_back(edge(from, 0, G[from].size() - 1));

    return id;
  }

  void bfs(int s) {
    queue<int> q;
    level.assign(MAX_V, -1);
    level[s] = 0;
    q.push(s);
    while(q.size()) {
      int v = q.front(); q.pop();
      for(edge e: G[v])
        {
          if(e.cap > 0 && level[e.to] < 0) {
            level[e.to] = level[v] + 1;
            q.push(e.to);
          }
        }
    }
  }

  int dfs(int v, int t, int f) {
    if(v == t) return f;
    for(int &i = itr[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
        int 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;
  }

  int solve(int s, int t) {
    int flow = 0, f;

    while(1) {
      bfs(s);
      if(level[t] < 0) return flow;
      itr.assign(MAX_V, 0);
      while((f = dfs(s, t, INF)) > 0) flow += f;
    }
  }

};


struct UF{
  vector<int> data;
  UF(int s): data(s, -1) {}

  int root(int x) {
    if(data[x] < 0) return x;
    return data[x] = root(data[x]);
  }

  bool set(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  bool check(int x, int y) {
    return root(x) == root(y);
  }
};

int h[SIZE], w[SIZE];
int x[SIZE], y[SIZE];

int main() {
  int N, M;

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

  int ans1 = 0, ans2 = 0;

  for(int i=0; i<1000; i++) h[i] = w[i] = -1;

  UF uf(M);

  for(int i=0; i<M; i++) {
    scanf("%d%d", x+i, y+i);
    x[i]--; y[i]--;

    if (h[y[i]] >= 0)
      ans1 += uf.set(h[y[i]], i);

    if (w[x[i]] >= 0)
      ans1 += uf.set(w[x[i]], i);

    h[y[i]] = i;
    w[x[i]] = i;
  }

  int K = 1000;

  Dinic dinic(K * 2 + M + 2);

  for(int i=0; i<M; i++) {
    dinic.add_edge(x[i], K*2 + i, 1);
    dinic.add_edge(K*2 + i, y[i] + K, 1);
  }

  for(int i=0; i<K; i++) {
    dinic.add_edge(K*2 + M, i, 1);
    dinic.add_edge(i + K, K*2 + M + 1, 1);
  }

  //cerr << dinic.solve(K*2+M, K*2+M+1) << endl;

  ans2 = M - dinic.solve(K*2+M, K*2+M+1);

  printf("%d %d\n", ans2, ans1);
}