#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 20;
const long long inf = 2e15;
long long d[N], inq[N];
queue<int> q;
long long n, m, k;
struct node {
  long long x, y;
} p[N];
long long SPFA() {
  for (int i = 1; i <= k; i++) d[i] = inf, inq[i] = 0;
  while (!q.empty()) q.pop();
  q.push(1), inq[1] = 1, d[1] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop(), inq[u] = 0;
    for (int i = 1; i <= k; i++) {
      if (i == u) continue;
      long long val = inf;
      int dx = abs(p[u].x - p[i].x), dy = abs(p[u].y - p[i].y);
      if (dx + dy == 1)
        val = 0;
      else if (dx <= 2 || dy <= 2)
        val = 1;
      if (d[i] > d[u] + val) {
        d[i] = d[u] + val;
        if (!inq[i]) inq[i] = 1, q.push(i);
      }
    }
  }
  if (d[k] == inf) d[k] = -1;
  return d[k];
}
int main() {
  while (cin >> n >> m >> k) {
    bool flag = false;
    for (int i = 1; i <= k; i++) {
      scanf("%I64d%I64d", &p[i].x, &p[i].y);
      if (p[i].x == n && p[i].y == m) flag = true;
    }
    if (flag == false) p[++k].x = n + 1, p[k].y = m + 1;
    cout << SPFA() << endl;
  }
  return 0;
}
