题目描述
Problem
The penguins Fluoro is in an infinitely wide ice cube ($ sx $, $ sy $).
There is a hole in the trout ($ tx $, $ ty $) through which water can enter.
There are $ n $ lumps of ice on the ice, each in the square ($ x_i $, $ y_i $).
Fluoro can move up, down, left and right in four directions.
It's slippery on the ice, so when you move it keeps moving until it hits a block of ice.
When it hits a lump of ice, it stops just before the square with the lump of ice.
You can enter the hole by passing through the square of the hole.
Fluoro can stop in the middle by stepping on it only once.
It hurts when it hits a lump of ice, so I want to reduce the number of hits as much as possible.
Find the minimum number of hits before moving to a square with a hole ($ tx $, $ ty $).
If you can't reach it, print $-$ 1.
Constraints
The input satisfies the following conditions.
- $0 \ leq n \ leq 10 ^ 5$
- $0 \$, $ sy $, $ tx $, $ ty $, $ x_i $, $y_i \ leq 10 ^ 9$
- All given coordinates are different
Input
The input is given in the following format.
$ sx $ $ sy $
$ tx $ $ ty $
$ n $
$ x_1 $ $ y_1 $
...
$ x_n $ $ y_n $
All inputs are given as integers.
The coordinates of the cell where Fluoro is on the first line are given separated by blanks.
The coordinates of the cells with holes in the second line are given separated by blanks.
The third line gives the number of ice cubes $ n $.
The coordinates of the square with the ice block on the following $ n $ line are given, separated by blanks.
Output
Output the minimum number of hits before moving to a hole.
If you can't reach it, print $-$ 1.
Examples
Input
0 0
13 33
2
0 34
14 0
Output
0
Input
0 1
5 0
4
2 1
1 3
4 2
3 0
Output
4
Input
0 0
0 2
1
0 1
Output
-1
输入格式
见题面
输出格式
见题面