{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003ch3\u003eProblem Statement\u003c/h3\u003e\n\u003cp\u003e\"\" is a single-player game and uses a chessboard which has $N \\times N$ grid and $M$ rook pieces.\u003c/p\u003e\n\u003cp\u003eA 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\u0027t distinguish between white and black, in other words, every rook can capture any of other rooks.\u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\u003ccenter\u003e\u003cimg src\u003d\"CDN_BASE_URL/d0ff46cfd4d344ee55cd273e17f8d5aa?v\u003d1715132638\" width\u003d\"400pt\"\u003e\u003c/center\u003e\u003cp\u003e\u003c/p\u003e\n\u003cp\u003eInitially, 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.\u003c/p\u003e\n\u003cp\u003eIn this problem, you are requested to calculate the minimum and maximum values of the number of captured rooks.\u003c/p\u003e\n\u003chr\u003e\n\u003ch3\u003eInput\u003c/h3\u003e\n\u003cp\u003eThe input consists of a single test case in the format below.\u003c/p\u003e\n\u003cblockquote\u003e$N$ $M$\n$x_{1}$ $y_{1}$\n$\\vdots$\n$x_{M}$ $y_{M}$\u003c/blockquote\u003e\n\u003cp\u003eThe 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.\u003c/p\u003e\n\u003ch3\u003eOutput\u003c/h3\u003e\n\u003cp\u003eOutput the minimum and maximum values of the number of captured rooks separated by a single space.\u003c/p\u003e\n\u003cp\u003e\u003c/p\u003e\u003cdiv class\u003d\"no-page-break\"\u003e\u003ch3\u003eExamples\u003c/h3\u003e\u003ctable class\u003d\"ioexample\"\u003e\u003ctbody\u003e\u003ctr\u003e\u003cth\u003eInput\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cpre\u003e8 3\n1 1\n1 8\n8 8\n\u003c/pre\u003e\u003c/td\u003e\u003ctd\u003e\u003cpre\u003e1 2\n\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cpre\u003e8 4\n1 1\n1 8\n8 8\n8 1\n\u003c/pre\u003e\u003c/td\u003e\u003ctd\u003e\u003cpre\u003e2 3\n\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cpre\u003e5 5\n1 1\n2 2\n3 3\n4 4\n5 5\n\u003c/pre\u003e\u003c/td\u003e\u003ctd\u003e\u003cpre\u003e0 0\n\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cpre\u003e100 1\n100 100\n\u003c/pre\u003e\u003c/td\u003e\u003ctd\u003e\u003cpre\u003e0 0\n\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cpre\u003e10 12\n1 2\n1 4\n1 6\n3 6\n5 6\n10 7\n8 7\n6 7\n4 7\n2 7\n7 3\n9 5\n\u003c/pre\u003e\u003c/td\u003e\u003ctd\u003e\u003cpre\u003e7 8\n\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003c/div\u003e\u003cp\u003e\u003c/p\u003e\n"}}]}