#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
inline int read() {
  int k = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    k = (k << 1) + (k << 3) + (ch ^ 48);
    ch = getchar();
  }
  return k * f;
}
struct node {
  int x, y;
} a[500050];
int vis[500050], dis[550050];
queue<int> q;
int n, m, k;
void spfa() {
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= k; i++) dis[i] = inf;
  dis[1] = 0;
  q.push(1);
  vis[1] = 1;
  while (!q.empty()) {
    int u = q.front();
    vis[u] = false;
    q.pop();
    for (int v = 1; v <= k; v++) {
      if (u == v) continue;
      int w = inf;
      int dx = abs(a[u].x - a[v].x);
      int dy = abs(a[u].y - a[v].y);
      if (dx + dy == 1)
        w = 0;
      else if (dx <= 2 || dy <= 2)
        w = 1;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        if (!vis[v]) {
          q.push(v);
          vis[v] = true;
        }
      }
    }
  }
  if (dis[k] == inf)
    puts("-1");
  else
    cout << dis[k] << endl;
}
int main() {
  cin >> n >> m >> k;
  int flag = 0;
  for (int i = 1; i <= k; i++) {
    a[i].x = read();
    a[i].y = read();
    if (a[i].x == n && a[i].y == m) flag = 1;
  }
  if (!flag) {
    a[++k].x = n + 1;
    a[k].y = m + 1;
  }
  spfa();
}
