#include <bits/stdc++.h>
using namespace std;
const long long N = 1e4 + 10;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
namespace FastIO {
template <typename tp>
inline void read(tp &x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
template <typename tp>
inline void write(tp x) {
  if (x == 0) return (void)(putchar('0'));
  if (x < 0) putchar('-'), x = -x;
  long long pr[20];
  register long long cnt = 0;
  for (; x; x /= 10) pr[++cnt] = x % 10;
  while (cnt) putchar(pr[cnt--] + '0');
}
template <typename tp>
inline void writeln(tp x) {
  write(x);
  putchar('\n');
}
}  // namespace FastIO
using namespace FastIO;
int n, m, k, flag, ans;
struct Node {
  int x, y;
} node[N];
int dis[N], vis[N];
void spfa() {
  memset(dis, 0x3f, sizeof(dis));
  dis[1] = 0;
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 1; i <= k; i++) {
      if (i == now) continue;
      int dx = abs(node[now].x - node[i].x);
      int dy = abs(node[now].y - node[i].y);
      int val = inf;
      if (dx + dy == 1)
        val = 0;
      else if (dx <= 2 || dy <= 2)
        val = 1;
      if (dis[i] > dis[now] + val) {
        dis[i] = dis[now] + val;
        q.push(i);
      }
    }
  }
  if (dis[k] < 10000)
    writeln(dis[k]);
  else
    puts("-1");
}
int main() {
  read(n), read(m), read(k);
  for (int i = 1; i <= k; i++) {
    read(node[i].x), read(node[i].y);
    if (node[i].x == n && node[i].y == m) flag = 1;
  }
  if (!flag) {
    node[++k].x = n + 1;
    node[k].y = m + 1;
  }
  spfa();
  return 0;
}
