Inner Vertices

Time limit2sMemory limit64 MB

Problem

There is an infinite square grid whose vertices are each colored either black or white.

Call a vertex $V$ horizontal-inner if its row contains two black vertices with $V$ strictly between them, and vertical-inner if its column contains two black vertices with $V$ strictly between them. A vertex is inner if it is both horizontal-inner and vertical-inner.

Repeat the following step: simultaneously turn every white inner vertex black, while all other vertices keep their color. The process stops once no white inner vertex remains.

Compute the number of black vertices once the process stops.

Input

The first line contains one integer $n$ ($0 \le n \le 100000$), the number of initially black vertices.

Each of the next $n$ lines contains two integers, the coordinates of a black vertex. All listed vertices are distinct, and every coordinate has absolute value at most $10^9$.

Output

Output the number of black vertices once the process stops. If the process never stops, output -1.

Hint