#include <bits/stdc++.h>
using namespace std;
int n, m, k, kq;
bool kiemtra = false;
vector<pair<int, int> > light;
vector<int> dist;
void nhap() {
  cin >> n >> m >> k;
  light.assign(k, pair<int, int>());
  dist.assign(k, 1e9);
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    light[i].first = x, light[i].second = y;
    if (x == n && y == m) kiemtra = true, kq = i;
  }
  if (!kiemtra) {
    light.push_back(make_pair(n + 1, m + 1));
    dist.push_back(1e9);
    k++;
  }
}
void dijkstra() {
  dist[0] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pair<int, int> top = pq.top();
    pq.pop();
    int d = top.first, tmp = top.second;
    if (d > dist[tmp]) continue;
    for (int i = 0; i < k; i++) {
      int u = light[i].first, v = light[i].second, val = 1e9;
      int tmp_x = light[tmp].first, tmp_y = light[tmp].second;
      if (tmp_x == u && tmp_y == v) continue;
      int kc_x = abs(u - tmp_x), kc_y = abs(v - tmp_y);
      if (kc_x + kc_y == 1)
        val = 0;
      else if (kc_x <= 2 || kc_y <= 2)
        val = 1;
      if (dist[tmp] + val < dist[i]) {
        dist[i] = dist[tmp] + val;
        pq.push(make_pair(dist[i], i));
      }
    }
  }
}
int main() {
  nhap();
  dijkstra();
  if (!kiemtra) {
    if (dist[k - 1] == 1e9) dist[k - 1] = -1;
    cout << dist[k - 1];
  } else {
    if (dist[kq] == 1e9) dist[kq] = -1;
    cout << dist[kq];
  }
}
