#include <bits/stdc++.h>
using namespace std;
const long long Llinf = LLONG_MAX;
const int Inf = INT_MAX;
const int Maxn = 1e4 + 10;
const int Mod = 1e9 + 7;
char* _c = new char[Maxn];
string GetString() {
  scanf("%s", _c);
  return string(_c);
}
int n, m, k;
int first[Maxn], second[Maxn];
map<pair<int, int>, int> M;
int parent[Maxn];
bool vis[Maxn];
int pntr;
int l[Maxn], r[Maxn], u[Maxn], d[Maxn];
int dist[Maxn];
int ans = Inf;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void Traverse(int first, int second, int p) {
  vis[p] = 1;
  parent[p] = pntr;
  for (int i = 0; i < 4; i++) {
    int new_x = first + dx[i], new_y = second + dy[i];
    if (M.find(pair<int, int>(new_x, new_y)) != M.end() &&
        !vis[M[pair<int, int>(new_x, new_y)]])
      Traverse(new_x, new_y, M[pair<int, int>(new_x, new_y)]);
  }
}
bool Valid(int a, int b, int dif) {
  bool _ = 1, __ = 1;
  if (l[a] > r[b] + dif || l[b] > r[a] + dif) _ = 0;
  if (u[a] > d[b] + dif || u[b] > d[a] + dif) __ = 0;
  return _ | __;
}
int main() {
  for (int i = 0; i < Maxn; i++) l[i] = u[i] = Inf, r[i] = d[i] = -Inf;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &first[i], &second[i]);
    M[pair<int, int>(first[i], second[i])] = i;
  }
  for (int i = 1; i <= k; i++)
    if (!vis[i]) ++pntr, Traverse(first[i], second[i], i);
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= k; i++) {
    l[parent[i]] = min(first[i], l[parent[i]]);
    r[parent[i]] = max(first[i], r[parent[i]]);
    u[parent[i]] = min(second[i], u[parent[i]]);
    d[parent[i]] = max(second[i], d[parent[i]]);
  }
  queue<int> Q;
  Q.push(parent[M[pair<int, int>(1, 1)]]);
  vis[parent[M[pair<int, int>(1, 1)]]] = 1;
  dist[parent[M[pair<int, int>(1, 1)]]] = 0;
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    for (int i = 1; i <= pntr; i++) {
      if (i != v && !vis[i] && Valid(v, i, 2)) {
        vis[i] = 1;
        dist[i] = dist[v] + 1;
        Q.push(i);
      }
    }
  }
  if (M.find(pair<int, int>(n, m)) == M.end()) {
    ++pntr;
    l[pntr] = r[pntr] = n;
    u[pntr] = d[pntr] = m;
    for (int i = 1; i < pntr; i++)
      if (vis[i] && Valid(i, pntr, 1)) ans = min(ans, dist[i] + 1);
    printf("%d\n", (ans == Inf) ? -1 : ans);
  } else
    printf("%d\n", dist[parent[M[pair<int, int>(n, m)]]]);
  return 0;
}
