#include <bits/stdc++.h>
using namespace std;
int INF = 1e9;
int N, M, K;
vector<int> dist;
vector<pair<int, int> > c;
int main() {
  ios::sync_with_stdio(0);
  cin >> N >> M >> K;
  for (int i = 0; i < K; i++) {
    int x, y;
    cin >> x >> y;
    c.push_back({x - 1, y - 1});
  }
  sort(c.begin(), c.end());
  if (c.back() != pair<int, int>(N - 1, M - 1)) c.push_back({N, M}), K++;
  dist.resize(K, INF);
  dist[0] = 0;
  deque<int> q;
  q.push_back(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (int v = 0; v < K; v++) {
      int dx = abs(c[u].first - c[v].first);
      int dy = abs(c[u].second - c[v].second);
      if (dx + dy <= 1) {
        if (dist[u] < dist[v]) dist[v] = dist[u], q.push_front(v);
      } else if (dx <= 2 || dy <= 2) {
        if (dist[u] + 1 < dist[v]) dist[v] = dist[u] + 1, q.push_back(v);
      }
    }
  }
  cout << (dist[K - 1] == INF ? -1 : dist[K - 1]) << endl;
  return 0;
}
