#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 100;
int n, m, k, root[10010], dist[10010], st, en;
pair<int, int> pnt[10010];
bitset<10010> edge[10010];
bool flag;
queue<int> Q;
bool adj(int r, int s) {
  if (!flag && (r == k || s == k)) return false;
  if (abs(pnt[r].first - pnt[s].first) + abs(pnt[r].second - pnt[s].second) <=
      1)
    return true;
  return false;
}
int find_root(int r) {
  if (root[r] == r) return r;
  return root[r] = find_root(root[r]);
}
bool con(int r, int s) {
  if (!flag && (r == k || s == k)) {
    if (abs(pnt[r].first - pnt[s].first) <= 1 ||
        abs(pnt[r].second - pnt[s].second) <= 1)
      return true;
    else
      return false;
  }
  if (abs(pnt[r].first - pnt[s].first) <= 2 ||
      abs(pnt[r].second - pnt[s].second) <= 2)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &pnt[i].first, &pnt[i].second);
    if (pnt[i].first == n && pnt[i].second == m) flag = 1, en = i;
    if (pnt[i].first == 1 && pnt[i].second == 1) st = i;
  }
  if (!flag) {
    k++;
    pnt[k].first = n;
    pnt[k].second = m;
    en = k;
  }
  for (int i = 1; i <= k; i++) root[i] = i;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      if (adj(i, j)) root[find_root(i)] = find_root(j);
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      if (find_root(i) != find_root(j)) {
        if (con(i, j)) {
          edge[find_root(i)][find_root(j)] = 1;
          edge[find_root(j)][find_root(i)] = 1;
        }
      }
    }
  }
  en = find_root(en);
  st = find_root(st);
  for (int i = 0; i <= k; i++) dist[i] = inf;
  while (!Q.empty()) Q.pop();
  Q.push(st);
  dist[st] = 0;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 1; i <= k; i++) {
      if (edge[x][i]) {
        if (dist[i] == inf) {
          dist[i] = dist[x] + 1;
          Q.push(i);
        }
      }
    }
  }
  if (dist[en] == inf)
    puts("-1");
  else
    printf("%d", dist[en]);
}
