#include <bits/stdc++.h>
using namespace std;
const int maxn = 11111;
vector<pair<int, int> > p;
vector<int> E[maxn];
int fa[maxn], d[maxn], N;
bool inQ[maxn];
int getfa(int x) {
  if (x == fa[x]) return x;
  return fa[x] = getfa(fa[x]);
}
bool isSame(int x, int y) { return getfa(x) == getfa(y); }
void merge(int x, int y) {
  x = getfa(x);
  y = getfa(y);
  fa[x] = y;
}
void spfa() {
  queue<int> Q;
  Q.push(0);
  inQ[0] = true;
  memset(d, 0x3f, sizeof(d));
  d[0] = 0;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i : E[u]) {
      int t = isSame(i, u) ? 0 : 1;
      if (d[i] > d[u] + t) {
        d[i] = d[u] + t;
        if (!inQ[i]) {
          inQ[i] = true;
          Q.push(i);
        }
      }
    }
    inQ[u] = false;
  }
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  bool flag = false;
  for (int i = 1; i <= k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == n && y == m) flag = true;
    p.push_back(make_pair(x, y));
  }
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (abs(p[i].first - p[j].first) <= 2 ||
          abs(p[i].second - p[j].second) <= 2) {
        E[i].push_back(j);
        E[j].push_back(i);
      }
    }
  }
  for (int i = 0; i < k; i++) fa[i] = i;
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second) <= 1)
        merge(i, j);
    }
  }
  spfa();
  if (flag == true) {
    printf("%d\n", d[k - 1] == d[maxn - 1] ? -1 : d[k - 1]);
  } else {
    int ans = d[maxn - 1];
    for (int i = 0; i < k; i++) {
      if (abs(p[i].first - n) <= 1 || abs(p[i].second - m) <= 1) {
        ans = min(ans, d[i] + 1);
      }
    }
    printf("%d\n", ans == d[maxn - 1] ? -1 : ans);
  }
  return 0;
}
