#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
template <class T>
inline T min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline T min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T>
inline T max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
const int N = 2e5;
const int M = 200005;
int n, m;
int K;
struct node {
  int x, y;
} p[N];
bool flag = false;
int dis[N];
int st = 1, se = 0;
int ins[N];
int ans = 0x3f3f3f3f;
void spfa(int x) {
  queue<int> que;
  memset(dis, 0x3f, sizeof(dis));
  ;
  dis[x] = 0;
  que.push(x);
  ins[x] = 1;
  while (!que.empty()) {
    int u = que.front();
    ins[u] = 0;
    que.pop();
    for (long long v = (1); v <= (K); v++) {
      if (v == u) continue;
      int w;
      if (abs(p[u].x - p[v].x) == 1 && p[u].y == p[v].y)
        w = 0;
      else if (abs(p[u].y - p[v].y) == 1 && p[u].x == p[v].x)
        w = 0;
      else if (abs(p[u].x - p[v].x) > 2 && abs(p[u].y - p[v].y) > 2)
        continue;
      else
        w = 1;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        if (!ins[v]) {
          que.push(v);
          ins[v] = 1;
        }
      }
    }
  }
}
int main() {
  cin >> n >> m >> K;
  for (long long i = (1); i <= (K); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    p[i].x = x;
    p[i].y = y;
    if (x == 1 && y == 1) st = i;
    if (x == n && y == m) se = i, flag = true;
  }
  spfa(st);
  if (flag) {
    if (dis[se] != 0x3f3f3f3f)
      cout << dis[se];
    else
      cout << -1;
    return 0;
  }
  se = K + 1;
  p[se].x = n;
  p[se].y = m;
  bool kk = 0;
  for (long long i = (1); i <= (K); i++) {
    int u = i;
    int v = se;
    if (!(abs(p[u].x - p[v].x) > 1 && abs(p[u].y - p[v].y) > 1)) {
      kk = 1;
      ans = min(ans, dis[u] + 1);
    }
  }
  if (kk && ans != 0x3f3f3f3f)
    cout << ans;
  else
    cout << -1;
  return 0;
}
