#include <bits/stdc++.h>
using namespace std;
int n, m, k;
map<pair<int, int>, int> id;
pair<int, int> f[10005];
int dist[10005];
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
vector<int> row[10005], col[10005];
int edist(pair<int, int> o, int x, int y) {
  int i = abs(x - o.first), j = abs(y - o.second);
  return i + j;
}
int sssp() {
  int st = id[make_pair(1, 1)];
  deque<int> q;
  if (id[make_pair(n, m)] == 0) {
    for (int i = n - 1; i <= n; i++) {
      if (i < 1 || i > n) continue;
      for (int j = 0; j < row[i].size(); j++) {
        int v = row[i][j];
        if (dist[v] > 1) {
          dist[v] = 1;
          q.push_back(v);
        }
      }
    }
    for (int i = m - 1; i <= m; i++) {
      if (i < 1 || i > m) continue;
      for (int j = 0; j < col[i].size(); j++) {
        int v = col[i][j];
        if (dist[v] > 1) {
          dist[v] = 1;
          q.push_back(v);
        }
      }
    }
  } else {
    q.push_back(id[make_pair(n, m)]);
    dist[id[make_pair(n, m)]] = 0;
  }
  int res = 1e9;
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    if (f[u].first == 1 && f[u].second == 1) res = min(res, dist[u]);
    for (int i = 0; i < 4; i++) {
      int nx = f[u].first + dx[i], ny = f[u].second + dy[i];
      pair<int, int> v = make_pair(nx, ny);
      if (id[v] > 0 && dist[id[v]] > dist[u]) {
        dist[id[v]] = dist[u];
        q.push_front(id[v]);
      }
    }
    for (int i = f[u].first - 2; i <= f[u].first + 2; i++) {
      if (i < 1 || i > n) continue;
      for (int j = 0; j < row[i].size(); j++) {
        int v = row[i][j];
        if (dist[v] > dist[u] + 1) {
          dist[v] = dist[u] + 1;
          q.push_back(v);
        }
      }
    }
    for (int i = f[u].second - 2; i <= f[u].second + 2; i++) {
      if (i < 1 || i > m) continue;
      for (int j = 0; j < col[i].size(); j++) {
        int v = col[i][j];
        if (dist[v] > dist[u] + 1) {
          dist[v] = dist[u] + 1;
          q.push_back(v);
        }
      }
    }
  }
  if (res == 1e9) return -1;
  return res;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    id[make_pair(x, y)] = i;
    dist[i] = 1e9;
    row[x].push_back(i);
    col[y].push_back(i);
    f[i] = make_pair(x, y);
  }
  printf("%d\n", sssp());
  return 0;
}
