#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e4 + 10;
int n, k, m;
int dis[maxn], vis[maxn], re1[maxn];
struct bkn {
  int x, d;
  friend bool operator<(bkn a, bkn b) { return a.d > b.d; }
};
struct node {
  int x, y, v;
  friend bool operator<(node a, node b) {
    if (a.x == b.x) return a.y < b.y;
    return a.x < b.x;
  }
} point[maxn], point2[maxn];
priority_queue<bkn> q;
int bin1(node point[], int x) {
  int l = 1, r = k;
  while (l < r) {
    int mid = (l + r) / 2;
    if (point[mid].x >= x)
      r = mid;
    else
      l = mid + 1;
  }
  if (point[l].x != x) return -1;
  return l;
}
int bin2(node point[], int x) {
  int l = 1, r = k;
  while (l < r) {
    int mid = (l + r) / 2 + 1;
    if (point[mid].x > x)
      r = mid - 1;
    else
      l = mid;
  }
  if (point[l].x != x) return -1;
  return l;
}
int bin3(node point[], int l, int r, int y) {
  if (l == -1 || r == -1) return -1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (point[mid].y == y)
      return mid;
    else if (point[mid].y > y)
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (point[l].y != y) return -1;
  return l;
}
void dj(node point[], int l, int r, int x, int y, int ord) {
  int i, ds;
  bkn gg;
  if (l == -1 || r == -1) return;
  for (i = l; i <= r; i++) {
    int o = point[i].v;
    if (abs(point[i].x - x) + abs(point[i].y - y) <= 1) ds = 0;
    if (dis[o] > dis[ord] + ds) {
      dis[o] = dis[ord] + ds;
      gg.x = o;
      gg.d = dis[o];
      q.push(gg);
    }
    ds = 1;
  }
}
void com(int x, int y, int d, int ord) {
  int l = bin1(point, x + d);
  int r = bin2(point, x + d);
  dj(point, l, r, x, y, ord);
  l = bin1(point2, y + d);
  r = bin2(point2, y + d);
  dj(point2, l, r, y, x, ord);
}
int main() {
  int i;
  int flag = 0;
  cin >> n >> m >> k;
  for (i = 1; i <= k; i++) {
    cin >> point[i].x >> point[i].y;
    point[i].v = i;
    point2[i].y = point[i].x;
    point2[i].x = point[i].y;
    point2[i].v = i;
  }
  sort(point + 1, point + k + 1);
  for (i = 1; i <= k; i++) re1[point[i].v] = i;
  sort(point2 + 1, point2 + k + 1);
  bkn gg;
  gg.x = 1;
  gg.d = 0;
  for (i = 1; i <= k; i++) dis[i] = 0x3fffffff;
  dis[1] = 0;
  q.push(gg);
  while (!q.empty()) {
    int x = point[re1[q.top().x]].x, y = point[re1[q.top().x]].y;
    int ord = q.top().x;
    q.pop();
    if (vis[ord]) continue;
    vis[ord] = 1;
    com(x, y, 0, ord);
    com(x, y, 1, ord);
    com(x, y, 2, ord);
    com(x, y, -1, ord);
    com(x, y, -2, ord);
  }
  int ans = 0x3fffffff;
  int qq = bin3(point, bin1(point, n), bin2(point, n), m);
  if (qq == -1) {
    int l = bin1(point, n);
    int r = bin2(point, n);
    if (l != -1) {
      for (i = l; i <= r; i++) {
        int o = point[i].v;
        ans = min(ans, dis[o] + 1);
      }
    }
    l = bin1(point2, m);
    r = bin2(point2, m);
    if (l != -1) {
      for (i = l; i <= r; i++) {
        int o = point2[i].v;
        ans = min(ans, dis[o] + 1);
      }
    }
    l = bin1(point, n - 1);
    r = bin2(point, n - 1);
    if (l != -1) {
      for (i = l; i <= r; i++) {
        int o = point[i].v;
        ans = min(ans, dis[o] + 1);
      }
    }
    l = bin1(point2, m - 1);
    r = bin2(point2, m - 1);
    if (l != -1) {
      for (i = l; i <= r; i++) {
        int o = point2[i].v;
        ans = min(ans, dis[o] + 1);
      }
    }
  } else {
    ans = dis[qq];
  }
  if (ans == 0x3fffffff)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
