#include <bits/stdc++.h>
using namespace std;
int n, m, k;
pair<int, int> pts[10002];
int dis[10001], mark[10001];
vector<pair<int, int> > litr[10001], litc[10001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> pts[i].first >> pts[i].second;
    dis[i] = 1e9;
    litr[pts[i].first].push_back(make_pair(pts[i].second, i));
    litc[pts[i].second].push_back(make_pair(pts[i].first, i));
  }
  pts[k + 1] = make_pair(n, m);
  dis[k + 1] = 1e9;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(make_pair(0, 1));
  while (!pq.empty()) {
    pair<int, int> xp = pq.top();
    pq.pop();
    int idx = xp.second;
    if (mark[idx]) continue;
    mark[idx] = 1;
    dis[idx] = xp.first;
    pair<int, int> cur = pts[idx];
    if (cur == make_pair(n, m)) {
      cout << xp.first << '\n';
      return 0;
    }
    int row = cur.first, col = cur.second;
    if (abs(row - n) <= 1 || abs(col - m) <= 1) {
      if (dis[k + 1] > xp.first + 1) {
        dis[k + 1] = xp.first + 1;
        pq.push(make_pair(xp.first + 1, k + 1));
      }
    }
    for (int i = max(1, row - 2); i <= min(row + 2, n); ++i) {
      for (pair<int, int> nxt : litr[i]) {
        int j = nxt.first, idnx = nxt.second;
        if (!mark[idnx] && dis[idnx] > xp.first + 1) {
          dis[idnx] = xp.first + 1;
          pq.push(make_pair(xp.first + 1, idnx));
        }
        if (!mark[idnx]) {
          if ((i == row && (j == col - 1 || j == col + 1)) ||
              (j == col && (i == row - 1 || i == row + 1))) {
            if (dis[idnx] > xp.first) {
              dis[idnx] = xp.first;
              pq.push(make_pair(xp.first, idnx));
            }
          }
        }
      }
    }
    for (int j = max(1, col - 2); j <= min(col + 2, m); ++j) {
      for (pair<int, int> nxt : litc[j]) {
        int i = nxt.first, idnx = nxt.second;
        if (!mark[idnx] && dis[idnx] > xp.first + 1) {
          dis[idnx] = xp.first + 1;
          pq.push(make_pair(xp.first + 1, idnx));
        }
      }
    }
  }
  cout << -1 << '\n';
}
