Mathematicians Alfred and Georg play a game. They take a white rectangular sheet of paper of size n × m divided into unit square cells. First, Alfred paints some of the cells black, and then Georg has to paint all the cells white again. To do that, Georg can perform the following operation an arbitrary number of times:
While Georg is working, Alfred mentally tries to count the smallest number of operations needed to finish the game starting from the initial configuration. He asked you to write a program that would answer this question.
The first line contains three integers n, m and k (1 ≤ n, m ≤ 500 000, 0 ≤ k ≤ 500 000) — the dimensions of the sheet, and the number of black cells respectively.
The subsequent k lines describe the black cells. The i-th of these lines contains two integers xi, yi — coordinates of the bottom left corner of the i-the black cell in the coordinate system described above (0 ≤ xi < n, 0 ≤ yi < m). It is guaranteed that all cells in the input are distinct.
Print one number — the smallest number of operations needed to finish the game. If it is impossible to paint the whole sheet white, print - 1.
2 2 3
0 0
1 0
1 1
1
2 2 3
0 0
0 1
1 1
2
2 2 3
1 0
0 1
1 1
3
In first sample one path is enough: (0, 0) → (0, 1) → (1, 1) → (1, 2) → (2, 2).
In the second sample two paths are enough: (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) and (0, 0) → (0, 2) → (2, 2).
| Name |
|---|


