#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 19260817;
const long long mod2 = 19660813;
int n;
int m;
int k;
int x[10005];
int y[10005];
void fun() {
  bool flag = false;
  for (int i = 1; i <= k; ++i)
    if (x[i] == n && y[i] == m) flag = true;
  if (flag == false) {
    ++k;
    x[k] = n + 1;
    y[k] = m + 1;
  }
}
queue<int> q;
int in[10005];
int dist[10005];
void spfa() {
  for (int i = 0; i < 10005; ++i) dist[i] = 0x3f3f3f3f;
  q.push(1);
  dist[1] = 0;
  in[1] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    in[u] = false;
    for (int i = 1; i <= k; ++i) {
      int dx = abs(x[u] - x[i]);
      int dy = abs(y[u] - y[i]);
      if (dx + dy == 1) {
        if (dist[i] > dist[u]) {
          dist[i] = dist[u];
          if (!in[i]) {
            q.push(i);
            in[i] = false;
          }
        }
      } else if (dx <= 2 || dy <= 2) {
        if (dist[i] > dist[u] + 1) {
          dist[i] = dist[u] + 1;
          if (!in[i]) {
            q.push(i);
            in[i] = false;
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= k; ++i) scanf("%d %d", x + i, y + i);
  fun();
  spfa();
  if (dist[k] == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", dist[k]);
  return 0;
}
