#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 3;
const int INF = 20010501;
int n, m, k, ax[MAXN], ay[MAXN], dis[MAXN];
bool vis[MAXN], jud;
std::queue<int> que;
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    cin >> ax[i] >> ay[i];
    if (ax[i] == n && ay[i] == m) jud = 1;
  }
  if (!jud) ax[++k] = n + 1, ay[k] = m + 1;
  for (int i = 1; i <= k; i++) dis[i] = INF;
  dis[1] = 0;
  vis[1] = 1;
  que.push(1);
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    vis[x] = 0;
    for (int i = 1; i <= k; i++) {
      if (i == x) continue;
      int v = INF,
          dx = ((ax[i] - ax[x]) > 0 ? (ax[i] - ax[x]) : -(ax[i] - ax[x])),
          dy = ((ay[i] - ay[x]) > 0 ? (ay[i] - ay[x]) : -(ay[i] - ay[x]));
      if (dx + dy == 1)
        v = 0;
      else if (dx <= 2 || dy <= 2)
        v = 1;
      if (dis[i] > dis[x] + v) {
        dis[i] = dis[x] + v;
        if (!vis[i]) {
          vis[i] = 1;
          que.push(i);
        }
      }
    }
  }
  if (dis[k] != INF)
    cout << dis[k];
  else
    cout << -1;
  return 0;
}
