#include <bits/stdc++.h>
using namespace std;
long long int dist[100001];
priority_queue<pair<long long int, long long int> > q;
pair<long long int, long long int> arr[100001];
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, m, k, x, y, ans, dis, cost;
  cin >> n >> m >> k;
  for (i = 1; i <= k; i++) cin >> arr[i].first >> arr[i].second;
  sort(arr + 1, arr + k + 1);
  for (i = 1; i <= k; i++) dist[i] = 1000000000000;
  dist[1] = 0;
  q.push({0, 1});
  while (!q.empty()) {
    x = q.top().second;
    dis = -q.top().first;
    q.pop();
    if (dist[x] != dis) continue;
    for (j = 1; j <= k; j++) {
      if (j == x) continue;
      if (abs(arr[x].first - arr[j].first) <= 2 ||
          abs(arr[x].second - arr[j].second) <= 2) {
        if (abs(arr[x].first - arr[j].first) +
                abs(arr[x].second - arr[j].second) ==
            1)
          cost = 0;
        else
          cost = 1;
        if (dist[j] > dis + cost) {
          dist[j] = dis + cost;
          q.push({-dist[j], j});
        }
      }
    }
  }
  ans = 1000000000000;
  if (arr[k] == make_pair(n, m))
    ans = dist[k];
  else {
    for (i = 1; i <= k; i++) {
      if (abs(arr[i].first - n) <= 1 || abs(arr[i].second - m) <= 1) {
        ans = min(ans, dist[i] + 1);
      }
    }
  }
  if (ans == 1000000000000) ans = -1;
  cout << ans;
  return 0;
}
