#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int maxn = 1e4 + 7;
const int INF = 0x3f3f3f3f;
vector<pii> nd;
int dis[maxn];
int main() {
  int n, m, k;
  bool ok = 0;
  scanf("%d%d%d", &n, &m, &k);
  memset(dis, 0x3f, sizeof(dis));
  for (int i = 0; i < k; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (u == n && v == m) ok = 1;
    nd.push_back({u, v});
  }
  sort(nd.begin(), nd.end());
  if (!ok) nd.push_back({n + 1, m + 1});
  priority_queue<pii, vector<pii>, greater<pii> > q;
  q.push({0, 0});
  dis[0] = 0;
  while (!q.empty()) {
    int d = q.top().first;
    int f = q.top().second;
    q.pop();
    if (d > dis[f]) continue;
    for (int i = 0; i < nd.size(); ++i) {
      int dx = abs(nd[i].first - nd[f].first);
      int dy = abs(nd[i].second - nd[f].second);
      int w;
      if (dx + dy == 1)
        w = 0;
      else if (dx <= 2 || dy <= 2)
        w = 1;
      else
        continue;
      if (dis[i] > d + w) {
        dis[i] = d + w;
        q.push({dis[i], i});
      }
    }
  }
  printf("%d\n", dis[nd.size() - 1] == INF ? -1 : dis[nd.size() - 1]);
  return 0;
}
