#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
  for (int i(0); i < N; i++) scanf("%d", A + i);
}
int N, M, K, a, b, sx[] = {1, -1, 0, 0}, sy[] = {0, 0, 1, -1}, x, y,
                   dx[] = {-1, 0, 1, 2, -2}, A[(10004)], B[(10004)], I,
                   C[(10004)], f = int(1e9 + 1);
vector<int> Q[(10004) * 4], X[(10004)], Y[(10004)];
short L[(10004)][(10004)];
int bfs() {
  Q->push_back(I);
  for (int i(0); i < (10004) * 3; i++)
    for (int j(0); j < int(Q[i].size()); j++) {
      I = Q[i][j], x = A[I], y = B[I];
      if (x + 1 == N && y + 1 == M) f = min(f, i);
      if (C[I]++) continue;
      for (int j(0); j < 4; j++) {
        a = x + sx[j], b = y + sy[j];
        if (!(~a && ~b && a < N && b < M) || !~L[a][b] || C[L[a][b]]) continue;
        Q[i].push_back(L[a][b]);
      }
      for (int j(0); j < 5; j++) {
        a = x + dx[j];
        if (a >= N || a < 0) continue;
        for (int h : X[a]) Q[i + 1].push_back(h);
        X[a].clear();
        if (j < 3 && a + 1 == N) f = min(i + 1, f);
      }
      for (int j(0); j < 5; j++) {
        a = y + dx[j];
        if (a >= M || a < 0) continue;
        for (auto &h : Y[a]) Q[i + 1].push_back(h);
        Y[a].clear();
        if (j < 3 && a + 1 == M) f = min(i + 1, f);
      }
    }
  return f > 4 * (10004) ? -1 : f;
}
int main(void) {
  scanf("%d%d%d", &N, &M, &K), (memset(C, 0, sizeof(C))),
      (memset(L, -1, sizeof(L)));
  for (int i(0); i < K; i++)
    scanf("%d%d", &a, &b), L[--a][--b] = i, A[i] = a, B[i] = b,
                           I = a | b ? I : i, X[a].push_back(i),
                           Y[b].push_back(i);
  printf("%d\n", bfs());
  return 0;
}
