#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
const int inf = 1e9 - 1;
int n, m, k;
int u[maxn], v[maxn];
int vis[maxn], d[maxn];
int SPFA(int start) {
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < maxn; i++) d[i] = inf;
  queue<int> que;
  while (!que.empty()) que.pop();
  que.push(start), d[start] = 0;
  vis[start] = 1;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    vis[x] = 0;
    for (int i = 1; i <= k; i++) {
      if (i == x) continue;
      int w = inf;
      int p = abs(u[i] - u[x]), q = abs(v[i] - v[x]);
      if (p + q == 1)
        w = 0;
      else if (p <= 2 || q <= 2)
        w = 1;
      if (d[i] > d[x] + w) {
        d[i] = d[x] + w;
        if (!vis[i]) {
          vis[i] = 1;
          que.push(i);
        }
      }
    }
  }
  return d[k] >= inf ? -1 : d[k];
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  memset(u, 0, sizeof(u));
  memset(v, 0, sizeof(v));
  int flag = 0;
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &u[i], &v[i]);
    if (u[i] == n && v[i] == m) flag = 1;
  }
  if (!flag) u[++k] = n + 1, v[k] = m + 1;
  int ans = SPFA(1);
  printf("%d\n", ans);
}
