#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
const int INF = 0x3f3f3f3f;
int x[MAXN], y[MAXN];
int n, m, k;
queue<int> q;
int vis[MAXN];
int dis[MAXN];
int SPFA() {
  while (!q.empty()) q.pop();
  memset(vis, 0, sizeof vis);
  memset(dis, 0x3f, sizeof dis);
  dis[1] = 0;
  vis[1] = 1;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 1; i <= k; i++) {
      if (i == u) continue;
      int dx = abs(x[u] - x[i]), dy = abs(y[u] - y[i]);
      int add = INF;
      if (dx <= 2 || dy <= 2) add = 1;
      if (dx + dy == 1) add = 0;
      if (dis[i] > dis[u] + add) {
        dis[i] = dis[u] + add;
        if (!vis[i]) {
          q.push(i);
          vis[i] = 1;
        }
      }
    }
  }
  if (dis[k] >= INF) dis[k] = -1;
  return dis[k];
}
int main() {
  cin >> n >> m >> k;
  int f = 0;
  for (int i = 1; i <= k; i++) {
    cin >> x[i] >> y[i];
    if (x[i] == n && y[i] == m) {
      f = 1;
    }
  }
  if (!f) {
    x[++k] = n + 1;
    y[k] = m + 1;
  }
  cout << SPFA() << endl;
  return 0;
}
