//============================================================================
// Name : POJ_3626_BFS.cpp
// Author : tiger
// Version :
// Copyright : Your copyright notice
// Description :简单的广搜
//============================================================================
#include <iostream>
#include <queue>
using namespace std;
int map[1001][1001] = {0};
bool f[1001][1001] = {false};
int X,Y;
struct point
{
int x,y;
int num;
};
queue<point> q;
int d[][2] = { {-1,0},{1,0},{0,1},{0,-1} };
bool valible(point t)
{
if(t.x < 0 || t.x > 1000 || t.y < 0 || t.y > 1000)
return false;
return true;
}
int bfs()
{
int i;
point t,tt;
t.x = 500;
t.y = 500;
t.num = 0;
f[t.x][t.y] = true;
q.push(t);
while(!q.empty())
{
t = q.front();
q.pop();
tt.num = t.num + 1;
for(i = 0; i < 4; i++)
{
tt.x = t.x + d[i][0];
tt.y = t.y + d[i][1];
if(tt.x == X && tt.y == Y)
return tt.num;
if(valible(tt) && f[tt.x][tt.y] == false && map[tt.x][tt.y] == 0)
{
q.push(tt);
f[tt.x][tt.y] = true;
}
}
}
return -1;
}
int main() {
freopen("in","r",stdin);
int i,N,x,y;
scanf("%d %d %d",&X,&Y,&N);
X += 500;
Y += 500;
for(i = 0; i < N; i++)
{
scanf("%d %d",&x,&y);
map[x+500][y+500] = 1;
}
printf("%d/n",bfs());
return 0;
}