#include <bits/stdc++.h>
using namespace std;
const int maxn = 11111;
int row[maxn], col[maxn], visited[maxn];
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int e = 0; e < k; e++) scanf("%d %d", row + e, col + e);
  int start = 0;
  for (int e = 1; e < k; e++)
    if (row[e] == 1 && col[e] == 1) start = e;
  int ans = maxn;
  deque<pair<int, int> > spfa;
  spfa.push_back(make_pair(start, 0));
  while (!spfa.empty()) {
    int cur, dist;
    tie(cur, dist) = spfa.front();
    spfa.pop_front();
    if (row[cur] == n && col[cur] == m) ans = min(ans, dist);
    if (row[cur] == n - 1 || col[cur] == m - 1 || row[cur] == n ||
        col[cur] == m)
      ans = min(ans, dist + 1);
    if (visited[cur]) continue;
    visited[cur] = true;
    for (int e = 0; e < k; e++) {
      if (visited[e]) continue;
      if (abs(row[e] - row[cur]) + abs(col[e] - col[cur]) == 1)
        spfa.push_front(make_pair(e, dist));
      if (abs(row[e] - row[cur]) <= 2 || abs(col[e] - col[cur]) <= 2)
        spfa.push_back(make_pair(e, dist + 1));
    }
  }
  if (ans == maxn) ans = -1;
  printf("%d\n", ans);
  return 0;
}
