#include <bits/stdc++.h>
using namespace std;
struct qu {
  int n, t;
} a, b, p[10010];
struct cmp {
  bool operator()(qu x, qu y) { return x.t > y.t; };
};
priority_queue<qu, vector<qu>, cmp> q;
int n, m, k, l, d[10010], r, e, g;
int dis(int x, int y) {
  int a = abs(p[x].n - p[y].n), b = abs(p[x].t - p[y].t);
  if (a > 2 && b > 2) return 1e9;
  if (a + b == 1) return 0;
  return 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  e = 1e9;
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &p[i].n, &p[i].t);
    if (p[i].n == 1 && p[i].t == 1) r = i;
    if (p[i].n == n && p[i].t == m) e = i;
  }
  if (e == 1e9) {
    e = k;
    p[e].n = n + 1;
    p[e].t = m + 1;
    k++;
  }
  for (int i = 0; i < k; i++) d[i] = 1e9;
  d[r] = 0;
  a.n = r;
  a.t = 0;
  q.push(a);
  while (!q.empty()) {
    b = q.top();
    q.pop();
    if (b.t != d[b.n]) continue;
    if (b.n == e) break;
    for (int i = 0; i < k; i++) {
      g = dis(b.n, i);
      if (d[i] > b.t + g) {
        d[i] = b.t + g;
        a.t = d[i];
        a.n = i;
        q.push(a);
      }
    }
  }
  if (d[e] == 1e9)
    printf("-1\n");
  else
    printf("%d\n", d[e]);
  return 0;
}
