#include <bits/stdc++.h>
using namespace std;
struct jj {
  int x, y;
} a[10000];
int flag = 1;
int cmp(struct jj x, struct jj y) {
  if (x.x < y.x) {
    return 1;
  } else if (x.x == y.x && x.y < y.y) {
    return 1;
  } else {
    return 0;
  }
}
int spfa(int s, int t) {
  int i, v[10001], dis[10001], w;
  queue<int> q;
  memset(v, 0, sizeof(v));
  memset(dis, 0x3f3f3f3f, sizeof(dis));
  q.push(s);
  dis[s] = 0;
  while (q.empty() == 0) {
    s = q.front();
    q.pop();
    v[s] = 0;
    for (i = 0; t >= i; i++) {
      if (t == i && flag == 1) {
        if (abs(a[i].x - a[s].x) <= 1 || abs(a[i].y - a[s].y) <= 1) {
          w = 1;
        } else {
          w = 0x3f3f3f3f;
        }
      } else if (abs(a[i].x - a[s].x) + abs(a[i].y - a[s].y) == 1) {
        w = 0;
      } else if (abs(a[i].x - a[s].x) <= 2 || abs(a[i].y - a[s].y) <= 2) {
        w = 1;
      } else {
        w = 0x3f3f3f3f;
      }
      if (dis[i] > dis[s] + w) {
        dis[i] = dis[s] + w;
        if (v[i] == 0) {
          v[i] = 1;
          q.push(i);
        }
      }
    }
  }
  if (dis[t] == 0x3f3f3f3f) {
    dis[t] = -1;
  }
  return dis[t];
}
int main() {
  int i, i1, n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (i = 0; k > i; i++) {
    scanf("%d %d", &a[i].x, &a[i].y);
    if (a[i].x == n && a[i].y == m) {
      flag = 0;
    }
  }
  if (flag == 1) {
    a[k].x = n;
    a[k].y = m;
    k++;
  }
  sort(a, a + k, cmp);
  printf("%d", spfa(0, k - 1));
  return 0;
}
