#include <bits/stdc++.h>
using namespace std;
const int N = 30010;
int n, m, k, x[N], y[N], nx[N], ny[N], tox[N], toy[N], pre[N], to[N * 20],
    nxt[N * 20], w[N * 20], cnt = 0, start;
int dis[N], vis[N];
queue<int> q;
bool cmp1(int a, int b) {
  if (x[a] != x[b])
    return x[a] < x[b];
  else
    return y[a] < y[b];
}
bool cmp2(int a, int b) {
  if (y[a] != y[b])
    return y[a] < y[b];
  else
    return x[a] < x[b];
}
void makeedge(int a, int b, int c) {
  to[cnt] = b, w[cnt] = c, nxt[cnt] = pre[a], pre[a] = cnt++;
}
int main() {
  memset(pre, -1, sizeof(pre));
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if (x[i] == 1 && y[i] == 1) start = i;
  }
  for (int i = 1; i <= k; i++) nx[i] = ny[i] = i;
  sort(nx + 1, nx + 1 + k, cmp1);
  for (int i = 1; i <= k; i++) tox[nx[i]] = i;
  sort(ny + 1, ny + 1 + k, cmp2);
  for (int i = 1; i <= k; i++) toy[ny[i]] = i;
  for (int i = 1; i <= k; i++) {
    int l, r, u, d;
    if (tox[i] > 1) {
      l = nx[tox[i] - 1];
      if (x[l] == x[i] && y[i] == y[l] + 1) makeedge(i, l, 0);
    }
    if (tox[i] < k) {
      r = nx[tox[i] + 1];
      if (x[r] == x[i] && y[i] == y[r] - 1) makeedge(i, r, 0);
    }
    if (toy[i] > 1) {
      u = ny[toy[i] - 1];
      if (y[u] == y[i] && x[i] == x[u] + 1) makeedge(i, u, 0);
    }
    if (toy[i] < k) {
      d = ny[toy[i] + 1];
      if (y[d] == y[i] && x[i] == x[d] - 1) makeedge(i, d, 0);
    }
    makeedge(i, x[i] + k, 1), makeedge(x[i] + k, i, 0);
    if (x[i] > 1) makeedge(i, x[i] + k - 1, 1), makeedge(x[i] + k - 1, i, 0);
    if (x[i] < n) makeedge(i, x[i] + k + 1, 1), makeedge(x[i] + k + 1, i, 0);
    makeedge(i, n + y[i] + k, 1), makeedge(n + y[i] + k, i, 0);
    if (y[i] > 1)
      makeedge(i, n + y[i] + k - 1, 1), makeedge(n + y[i] + k - 1, i, 0);
    if (y[i] < m)
      makeedge(i, n + y[i] + k + 1, 1), makeedge(n + y[i] + k + 1, i, 0);
  }
  memset(dis, 0x3f, sizeof(dis));
  q.push(start);
  dis[start] = 0, vis[start] = 1;
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    vis[a] = 0;
    for (int it = pre[a]; ~it; it = nxt[it]) {
      int b = to[it];
      if (dis[b] > dis[a] + w[it]) {
        dis[b] = dis[a] + w[it];
        if (!vis[b]) q.push(b), vis[b] = 1;
      }
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= k; i++) {
    if (x[i] == n && y[i] == m)
      ans = min(ans, dis[i]);
    else if (x[i] == n && y[i] != m)
      ans = min(ans, dis[i] + 1);
    else if (x[i] != n && y[i] == m)
      ans = min(ans, dis[i] + 1);
  }
  ans = min(ans, dis[n + k]), ans = min(ans, dis[n + m + k]);
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%d\n", ans);
  return 0;
}
