#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m, k, ri, ci;
  cin >> n >> m >> k;
  vector<int> row[n + 1], col[m + 1], dist(k), vis(k, false);
  vector<pair<int, int> > mapping(k);
  map<pair<int, int>, int> ulta;
  for (int i = 0; i < k; i++) {
    cin >> ri >> ci;
    row[ri].push_back(ci);
    col[ci].push_back(ri);
    mapping[i] = pair<int, int>(ri, ci);
    ulta[pair<int, int>(ri, ci)] = i;
    dist[i] = 1000000000;
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(pair<int, int>(0, ulta[pair<int, int>(1, 1)]));
  dist[ulta[pair<int, int>(1, 1)]] = 0;
  while (!pq.empty()) {
    pair<int, int> t = pq.top();
    pq.pop();
    pair<int, int> p = mapping[t.second];
    int x = p.first, y = p.second;
    if (x == n && y == m) break;
    if (vis[t.second]) continue;
    for (int i = 0; i < k; i++) {
      pair<int, int> p1 = mapping[i];
      int x1 = p1.first, y1 = p1.second;
      if (abs(x - x1) <= 2 || abs(y - y1) <= 2) {
        int d = 0;
        if (x == x1)
          d = (abs(y - y1)) > 1;
        else if (y == y1)
          d = (abs(x - x1)) > 1;
        else
          d = 1;
        if (t.first + d < dist[i]) {
          dist[i] = t.first + d;
          pq.push(pair<int, int>(t.first + d, i));
        }
      }
    }
    vis[t.second] = 1;
  }
  int ans = -1;
  if (ulta.find(pair<int, int>(n, m)) != ulta.end()) {
    if (dist[ulta[pair<int, int>(n, m)]] < 1000000000)
      ans = dist[ulta[pair<int, int>(n, m)]];
  } else {
    ans = 1000000000;
    for (int i = 0; i < row[n - 1].size(); i++)
      ans = min(ans, dist[ulta[pair<int, int>(n - 1, row[n - 1][i])]] + 1);
    for (int i = 0; i < row[n].size(); i++)
      ans = min(ans, dist[ulta[pair<int, int>(n, row[n][i])]] + 1);
    for (int i = 0; i < col[m - 1].size(); i++)
      ans = min(ans, dist[ulta[pair<int, int>(col[m - 1][i], m - 1)]] + 1);
    for (int i = 0; i < col[m].size(); i++)
      ans = min(ans, dist[ulta[pair<int, int>(col[m][i], m)]] + 1);
    if (ans == 1000000000) ans = -1;
  }
  cout << ans << endl;
  return 0;
}
