#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
const double EPS = 1e-9;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a < b ? -1 : 1; }
int n, m, k, a[N], b[N], d[N];
vector<int> row[N], col[N];
int xd[] = {1, -1, 0, 0};
int yd[] = {0, 0, 1, -1};
int get_cost(int i, int j) {
  if (abs(a[i] - a[j]) + abs(b[i] - b[j]) <= 1) return 0;
  return 1;
}
void bfs() {
  memset(d, -1, sizeof(d));
  deque<int> q;
  for (int i = 0; i < k; i++)
    if (a[i] == 0 && b[i] == 0) d[i] = 0, q.push_front((i));
  a[k] = n - 1;
  b[k] = m - 1;
  int xd[] = {1, -1, 0, 0};
  int yd[] = {0, 0, 1, -1};
  while (!q.empty()) {
    int top = q.front();
    q.pop_front();
    for (int i = -2; i < 3; i++) {
      int A = i + a[top];
      if (A < 0 || A == n) continue;
      for (int j = 0; j < row[A].size(); j++) {
        int idx = row[A][j];
        if (d[idx] == -1 || d[idx] > d[top] + get_cost(top, idx)) {
          d[idx] = d[top] + get_cost(top, idx);
          if (get_cost(top, idx))
            q.push_back(idx);
          else
            q.push_front(idx);
        }
      }
    }
    for (int i = -2; i < 3; i++) {
      int B = i + b[top];
      if (B < 0 || B == m) continue;
      for (int j = 0; j < col[B].size(); j++) {
        int idx = col[B][j];
        if (d[idx] == -1 || d[idx] > d[top] + get_cost(top, idx)) {
          d[idx] = d[top] + get_cost(top, idx);
          if (get_cost(top, idx))
            q.push_back(idx);
          else
            q.push_front(idx);
        }
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
    row[a[i]].push_back(i);
    col[b[i]].push_back(i);
  }
  bfs();
  for (int i = 0; i < k; i++) {
    if (a[i] == n - 1 && b[i] == m - 1) {
      printf("%d", d[i]);
      return 0;
    }
  }
  int mn = n * m * 2;
  for (int i = 0; i < k; i++) {
    if ((a[i] >= n - 2 || b[i] >= m - 2) && d[i] != -1) {
      mn = min(mn, d[i]);
    }
  }
  if (mn == n * m * 2)
    cout << -1;
  else
    cout << mn + 1;
  return 0;
}
