#include <bits/stdc++.h>
using namespace std;
int n, m, k;
set<int> row[10005], col[10005];
vector<int> rows[10005], cols[10005];
struct node1 {
  int r, c, litr, litc, d;
  bool operator<(const node1& x) const { return d > x.d; }
};
struct node2 {
  int r, c, litr, litc, d;
  bool operator<(const node2& x) const {
    if (r != x.r) return r > x.r;
    if (c != x.c) return c > x.c;
    if (litr != x.litr) return litr > x.litr;
    return litc > x.litc;
  }
};
map<node2, bool> vis;
bool inside(node1& x) {
  int r = x.r, c = x.c;
  return r >= 1 && r <= n && c >= 1 && c <= m || x.litr >= 1 && x.litr <= n ||
         x.litc >= 1 && x.litc <= m;
}
int dijkstra() {
  priority_queue<node1> qu;
  qu.push((node1){1, 1, 0, 0, 0});
  while (!qu.empty()) {
    node1 x = qu.top();
    qu.pop();
    node2 y = (node2){x.r, x.c, x.litr, x.litc, 0};
    if (vis[y]) continue;
    vis[y] = 1;
    if (x.r == n && x.c == m || x.litr == n || x.litc == m) return x.d;
    node1 z;
    if (x.litr == 0 && x.litc == 0) {
      if (row[x.r - 1].count(x.c)) {
        z = x;
        z.r = x.r - 1;
        if (inside(z)) qu.push(z);
      } else {
        z = x;
        z.r = z.c = 0;
        z.litr = x.r - 1;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
        z = x;
        z.r = z.c = 0;
        z.litc = x.c;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
      }
      if (row[x.r + 1].count(x.c)) {
        z = x;
        z.r = x.r + 1;
        if (inside(z)) qu.push(z);
      } else {
        z = x;
        z.r = z.c = 0;
        z.litr = x.r + 1;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
        z = x;
        z.r = z.c = 0;
        z.litc = x.c;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
      }
      if (col[x.c - 1].count(x.r)) {
        z = x;
        z.c = x.c - 1;
        if (inside(z)) qu.push(z);
      } else {
        z = x;
        z.c = z.r = 0;
        z.litc = x.c - 1;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
        z = x;
        z.r = z.c = 0;
        z.litr = x.r;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
      }
      if (col[x.c + 1].count(x.r)) {
        z = x;
        z.c = x.c + 1;
        if (inside(z)) qu.push(z);
      } else {
        z = x;
        z.c = z.r = 0;
        z.litc = x.c + 1;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
        z = x;
        z.r = z.c = 0;
        z.litr = x.r;
        z.d = x.d + 1;
        if (inside(z)) qu.push(z);
      }
    } else if (x.litr) {
      for (int i = 0; i < rows[x.litr - 1].size(); i++) {
        z.r = x.litr - 1;
        z.c = rows[x.litr - 1][i];
        z.litc = z.litr = 0;
        z.d = x.d;
        if (inside(z)) qu.push(z);
      }
      for (int i = 0; i < rows[x.litr + 1].size(); i++) {
        z.r = x.litr + 1;
        z.c = rows[x.litr + 1][i];
        z.litc = z.litr = 0;
        z.d = x.d;
        if (inside(z)) qu.push(z);
      }
    } else if (x.litc) {
      for (int i = 0; i < cols[x.litc - 1].size(); i++) {
        z.c = x.litc - 1;
        z.r = cols[x.litc - 1][i];
        z.litc = z.litr = 0;
        z.d = x.d;
        if (inside(z)) qu.push(z);
      }
      for (int i = 0; i < cols[x.litc + 1].size(); i++) {
        z.c = x.litc + 1;
        z.r = cols[x.litc + 1][i];
        z.litc = z.litr = 0;
        z.d = x.d;
        if (inside(z)) qu.push(z);
      }
    }
  }
  return -1;
}
int main() {
  int a, b;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &a, &b);
    row[a].insert(b);
    col[b].insert(a);
    rows[a].push_back(b);
    cols[b].push_back(a);
  }
  cout << dijkstra() << endl;
  return 0;
}
