#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
struct State {
  int row, col, pay;
  State() {}
  State(int a, int b, int c) {
    row = a;
    col = b;
    pay = c;
  }
  bool operator<(State o) const { return pay > o.pay; }
};
bool close(State a, State b) {
  return (a.row == b.row && abs(a.col - b.col) == 1) ||
         (a.col == b.col && abs(a.row - b.row) == 1);
}
int n, m, k, ans = -1;
vector<vector<State> > litRows(maxn), litCols(maxn);
bool initLit;
map<pair<int, int>, int> vis;
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    State ns = State(a, b, -1);
    litRows[a].push_back(ns);
    litCols[b].push_back(ns);
    vis[make_pair(a, b)] = INT_MAX;
  }
  priority_queue<State> q;
  q.push(State(1, 1, 0));
  bool reachone = false;
  int roval = INT_MAX;
  vis[make_pair(1, 1)] = 0;
  while (q.size() > 0) {
    State p = q.top();
    q.pop();
    if (p.row == n && p.col == m) {
      ans = p.pay;
      break;
    } else if (p.row == n || p.col == m || p.row == n - 1 || p.col == m - 1) {
      reachone = true;
      roval = min(roval, p.pay + 1);
    }
    for (int row = p.row - 2; row <= p.row + 2; row++) {
      if (row < 0 || row > n) continue;
      for (int j = 0; j < litRows[row].size(); j++) {
        State cs = litRows[row][j];
        cs.pay = p.pay + (close(p, cs) ? 0 : 1);
        if (vis[make_pair(cs.row, cs.col)] <= cs.pay) continue;
        vis[make_pair(cs.row, cs.col)] = cs.pay;
        q.push(cs);
      }
    }
    for (int col = p.col - 2; col <= p.col + 2; col++) {
      if (col < 0 || col > m) continue;
      for (int j = 0; j < litCols[col].size(); j++) {
        State cs = litCols[col][j];
        cs.pay = p.pay + (close(p, cs) ? 0 : 1);
        if (vis[make_pair(cs.row, cs.col)] <= cs.pay) continue;
        vis[make_pair(cs.row, cs.col)] = cs.pay;
        q.push(cs);
      }
    }
  }
  if (ans == -1 && reachone) ans = roval;
  cout << (ans) << endl;
  return 0;
}
