#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int inf = 0x3f3f3f3f;
int n, m, k;
struct node {
  int x, y;
} p[10001];
int dis[10001], vis[10001];
void bfs() {
  queue<int> s;
  s.push(0);
  vis[0] = 1;
  dis[0] = 0;
  while (!s.empty()) {
    int temp = s.front();
    s.pop();
    vis[temp] = 0;
    for (int i = 0; i < k; i++) {
      if (i == temp) continue;
      int t = inf;
      if (abs(p[temp].x - p[i].x) + abs(p[temp].y - p[i].y) == 1) {
        t = 0;
      } else if (abs(p[temp].x - p[i].x) <= 2 || abs(p[temp].y - p[i].y) <= 2) {
        t = 1;
      }
      if (dis[i] > dis[temp] + t) {
        dis[i] = dis[temp] + t;
        if (!vis[i]) {
          vis[i] = 1;
          s.push(i);
        }
      }
    }
  }
}
int main() {
  memset(vis, 0, sizeof(vis));
  memset(dis, inf, sizeof(dis));
  scanf("%d %d %d", &n, &m, &k);
  int flag = 0;
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &p[i].x, &p[i].y);
    if (p[i].x == n && p[i].y == m) flag = 1;
  }
  if (!flag) {
    p[k].x = n + 1, p[k].y = m + 1;
    k++;
  }
  bfs();
  if (dis[k - 1] == inf)
    printf("-1\n");
  else {
    printf("%d\n", dis[k - 1]);
  }
  return 0;
}
