#include <bits/stdc++.h>
using namespace std;
const int N = 10007;
int n, m, k, dist[N], ok;
pair<int, int> vertice[N];
int calc(int i, int j) {
  if (i > j) swap(i, j);
  if (j == k && !ok) {
    if (abs(vertice[i].first - vertice[j].first) < 2 ||
        abs(vertice[i].second - vertice[j].second) < 2)
      return 1;
    return 100000;
  }
  if (abs(vertice[i].first - vertice[j].first) +
          abs(vertice[i].second - vertice[j].second) <
      2)
    return 0;
  if (abs(vertice[i].first - vertice[j].first) <= 2 ||
      abs(vertice[i].second - vertice[j].second) <= 2)
    return 1;
  return 100000;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; ++i)
    cin >> vertice[i].first >> vertice[i].second,
        ok |= (vertice[i].first == n && vertice[i].second == m);
  if (!ok) ++k, vertice[k].first = n, vertice[k].second = m;
  sort(vertice + 1, vertice + k + 1);
  for (int i = 2; i <= k; ++i) dist[i] = 100000;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  q.push(make_pair(0, 1));
  while (!q.empty()) {
    pair<int, int> u = q.top();
    q.pop();
    if (dist[u.second] != u.first) continue;
    for (int i = 2; i <= k; ++i)
      if (dist[i] > dist[u.second] + calc(i, u.second))
        dist[i] = dist[u.second] + calc(i, u.second),
        q.push(make_pair(dist[i], i));
  }
  cout << (dist[k] == 100000 ? -1 : dist[k]) << endl;
  return 0;
}
