#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
map<pair<int, int>, int> mp;
int n, m, k, x[10010], y[10010], sz, first[30010], nxt[200010], tail[200010],
    len[200010], d[30010], q[100000];
void addedge(int u, int v, int l);
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int i, j, s = 0, t = 0;
  for (i = 1; i <= k; i++) {
    scanf("%d%d", &x[i], &y[i]);
    mp[pair<int, int>(x[i], y[i])] = i;
    if (x[i] == 1 && y[i] == 1) s = i;
    if (x[i] == n && y[i] == m) t = i;
  }
  memset(first, 0, sizeof(first));
  for (sz = 0, i = 1; i <= k; i++) {
    if (mp[pair<int, int>(x[i] - 1, y[i])])
      addedge(i, mp[pair<int, int>(x[i] - 1, y[i])], 0);
    if (mp[pair<int, int>(x[i] + 1, y[i])])
      addedge(i, mp[pair<int, int>(x[i] + 1, y[i])], 0);
    if (mp[pair<int, int>(x[i], y[i] - 1)])
      addedge(i, mp[pair<int, int>(x[i], y[i] - 1)], 0);
    if (mp[pair<int, int>(x[i], y[i] + 1)])
      addedge(i, mp[pair<int, int>(x[i], y[i] + 1)], 0);
    for (j = -1; j <= 1; j++)
      if (x[i] + j >= 1 && x[i] + j <= n) {
        addedge(i, k + x[i] + j, 1);
        addedge(k + x[i] + j, i, 0);
      }
    for (j = -1; j <= 1; j++)
      if (y[i] + j >= 1 && y[i] + j <= m) {
        addedge(i, k + n + y[i] + j, 1);
        addedge(k + n + y[i] + j, i, 0);
      }
  }
  memset(d, 0x3f, sizeof(d));
  int front = k + n + m, rear = k + n + m, u, v, e;
  d[s] = 0;
  q[k + n + m] = s;
  while (front <= rear) {
    u = q[front++];
    for (e = first[u]; e; e = nxt[e]) {
      v = tail[e];
      if (d[v] < INF) continue;
      d[v] = d[u] + len[e];
      if (len[e])
        q[++rear] = v;
      else
        q[--front] = v;
    }
  }
  int ans = min(d[k + n], d[k + n + m]);
  if (t) ans = min(ans, d[t]);
  printf("%d\n", ans < INF ? ans : -1);
  return 0;
}
void addedge(int u, int v, int l) {
  sz++;
  tail[sz] = v;
  len[sz] = l;
  nxt[sz] = first[u];
  first[u] = sz;
}
