#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e4 + 11;
vector<int> row[maxN];
vector<int> col[maxN];
map<pair<int, int>, int> M;
pair<int, int> points[maxN];
int mindist[maxN];
int visr[maxN];
int visc[maxN];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i < k + 1; i++) {
    int a, b;
    cin >> a >> b;
    row[a].push_back(i);
    row[a - 1].push_back(i);
    row[a + 1].push_back(i);
    col[b].push_back(i);
    col[b - 1].push_back(i);
    col[b + 1].push_back(i);
    M[make_pair(a, b)] = i;
    points[i] = make_pair(a, b);
  }
  int start = M[{1, 1}];
  fill(mindist, mindist + k + 1, 1e9);
  queue<int> q, q2;
  q.push(start);
  int dist_so_far = 0;
  while (!q.empty()) {
    while (!q.empty()) {
      int node = q.front();
      q.pop();
      int a = points[node].first;
      int b = points[node].second;
      for (int i = 0; i < 4; i++) {
        int na = a + dx[i];
        int nb = b + dy[i];
        if (M.find(make_pair(na, nb)) != M.end()) {
          if (mindist[M[{na, nb}]] > dist_so_far) {
            mindist[M[{na, nb}]] = dist_so_far;
            q.push(M[{na, nb}]);
          }
        }
      }
      for (int lit = -1; lit <= 1; lit++) {
        int na = a + lit;
        int nb = b + lit;
        if (!visr[na]) {
          visr[na] = 1;
          for (int r : row[na]) {
            if (mindist[r] > dist_so_far + 1) {
              mindist[r] = dist_so_far + 1;
              q2.push(r);
            }
          }
        }
        if (!visc[nb]) {
          visc[nb] = 1;
          for (int c : col[nb]) {
            if (mindist[c] > dist_so_far + 1) {
              mindist[c] = dist_so_far + 1;
              q2.push(c);
            }
          }
        }
      }
    }
    dist_so_far++;
    while (!q2.empty()) {
      int node = q2.front();
      q2.pop();
      q.push(node);
    }
  }
  int ans = 1e9;
  for (int i = 1; i < k + 1; i++) {
    if (points[i].first == n || points[i].first == n - 1)
      ans = min(ans, mindist[i] + 1);
    if (points[i].second == m || points[i].second == m - 1)
      ans = min(ans, mindist[i] + 1);
    if (points[i].first == n && points[i].second == m)
      ans = min(ans, mindist[i]);
  }
  if (ans == 1e9) ans = -1;
  cout << ans << "\n";
  return 0;
}
