#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> r[10005], c[10005];
bool ch[10005][10005], ok = 0;
map<pair<int, int>, int> d;
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;
    r[x].push_back(y);
    c[y].push_back(x);
    if (x == n && y == m) ok = 1;
  }
  priority_queue<pair<int, pair<int, int> >,
                 vector<pair<int, pair<int, int> > >,
                 greater<pair<int, pair<int, int> > > >
      qu;
  d[pair<int, int>(1, 1)] = 0;
  qu.push(pair<int, pair<int, int> >(0, pair<int, int>(1, 1)));
  while (!qu.empty()) {
    int x = qu.top().second.first;
    int y = qu.top().second.second;
    int du = qu.top().first;
    qu.pop();
    if (ok == 0) {
      if (x == n - 1 || y == m - 1 || x == n || y == m) {
        if (ch[n][m] == 0) {
          d[pair<int, int>(n, m)] = du + 1;
          qu.push(pair<int, pair<int, int> >(du + 1, pair<int, int>(n, m)));
          ch[n][m] = 1;
        } else if (d[pair<int, int>(n, m)] > du + 1) {
          d[pair<int, int>(n, m)] = du + 1;
          qu.push(pair<int, pair<int, int> >(du + 1, pair<int, int>(n, m)));
        }
      }
    }
    for (int i = max(1, x - 2); i <= min(n, x + 2); i++) {
      for (int j = 0; j < r[i].size(); j++) {
        int nx = i, ny = r[i][j], nd = 1;
        if (y == ny && (nx == x + 1 || nx == x - 1)) nd--;
        if (ch[nx][ny] == 0) {
          d[pair<int, int>(nx, ny)] = du + nd;
          qu.push(pair<int, pair<int, int> >(du + nd, pair<int, int>(nx, ny)));
          ch[nx][ny] = 1;
        } else if (d[pair<int, int>(nx, ny)] > du + nd) {
          d[pair<int, int>(nx, ny)] = du + nd;
          qu.push(pair<int, pair<int, int> >(du + nd, pair<int, int>(nx, ny)));
        }
      }
    }
    for (int i = max(1, y - 2); i <= min(m, y + 2); i++) {
      for (int j = 0; j < c[i].size(); j++) {
        int nx = c[i][j], ny = i, nd = 1;
        if (x == nx && (ny == y + 1 || ny == y - 1)) nd--;
        if (ch[nx][ny] == 0) {
          d[pair<int, int>(nx, ny)] = du + nd;
          qu.push(pair<int, pair<int, int> >(du + nd, pair<int, int>(nx, ny)));
          ch[nx][ny] = 1;
        } else if (d[pair<int, int>(nx, ny)] > du + nd) {
          d[pair<int, int>(nx, ny)] = du + nd;
          qu.push(pair<int, pair<int, int> >(du + nd, pair<int, int>(nx, ny)));
        }
      }
    }
  }
  int ans = d[pair<int, int>(n, m)];
  if (ch[n][m] == 0)
    cout << -1;
  else
    cout << ans;
  return 0;
}
