#include <bits/stdc++.h>
using namespace std;
const int N = 10010, INF = 1e9 + 7;
int n, m, k, start, d[N], ans;
vector<int> Vx[N], Vy[N];
vector<pair<int, int> > V;
map<pair<int, int>, int> num;
priority_queue<pair<int, int> > q;
void Dijkstra() {
  for (int i = 1; i <= k + 1; i++) d[i] = INF;
  d[start] = 0;
  q.push(pair<int, int>(start, d[start]));
  while (!q.empty()) {
    int u = q.top().first, du = q.top().second;
    q.pop();
    if (d[u] != du) continue;
    int x = V[u - 1].first, y = V[u - 1].second;
    for (int t = -2; t <= 2; t++) {
      for (int i = 0; x + t >= 1 && i < Vx[x + t].size(); i++) {
        int v = num[pair<int, int>(x + t, Vx[x + t][i])];
        int c = 1;
        if (abs(t) + abs(Vx[x + t][i] - y) <= 1) c = 0;
        if (d[v] > d[u] + c) {
          d[v] = d[u] + c;
          q.push(pair<int, int>(v, d[v]));
        }
      }
      for (int i = 0; y + t >= 1 && i < Vy[y + t].size(); i++) {
        int v = num[pair<int, int>(Vy[y + t][i], y + t)];
        int c = 1;
        if (abs(t) + abs(Vy[y + t][i] - x) <= 1) c = 0;
        if (d[v] > d[u] + c) {
          d[v] = d[u] + c;
          q.push(pair<int, int>(v, d[v]));
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    num[pair<int, int>(x, y)] = i;
    Vx[x].push_back(y);
    Vy[y].push_back(x);
    V.push_back(pair<int, int>(x, y));
  }
  start = num[pair<int, int>(1, 1)], ans = INF;
  Dijkstra();
  if (!num[pair<int, int>(n, m)]) {
    for (int t = 0; t <= 1; t++) {
      for (int i = 0; i < Vx[n - t].size(); i++) {
        int v = num[pair<int, int>(n - t, Vx[n - t][i])];
        ans = min(ans, d[v] + 1);
      }
      for (int i = 0; i < Vy[m - t].size(); i++) {
        int v = num[pair<int, int>(Vy[m - t][i], m - t)];
        ans = min(ans, d[v] + 1);
      }
    }
  } else
    ans = d[num[pair<int, int>(n, m)]];
  if (ans < INF)
    cout << ans;
  else
    cout << -1;
  return 0;
}
