#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int INF = 0x3f3f3f3f;
pair<int, int> p[maxn];
map<pair<int, int>, int> mp;
struct edge {
  int to, cost;
  edge() {}
  edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> G[maxn];
int nx[5] = {1, -1, 0, 0};
int ny[5] = {0, 0, 1, -1};
int dis[maxn];
bool vis[maxn];
void dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  memset(dis, 63, sizeof(dis));
  memset(vis, false, sizeof(vis));
  dis[s] = 0;
  q.push(pair<int, int>(s, 0));
  while (!q.empty()) {
    pair<int, int> tem = q.top();
    q.pop();
    int v = tem.first;
    if (dis[v] < tem.second) continue;
    vis[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (dis[e.to] > dis[v] + e.cost) {
        dis[e.to] = dis[v] + e.cost;
        q.push(pair<int, int>(e.to, dis[e.to]));
      }
    }
  }
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  mp.clear();
  int dd = 1e4 + 5;
  for (int i = 1; i <= k; i++) {
    int r, c;
    scanf("%d%d", &r, &c);
    G[i].push_back(edge(r + dd, 1));
    G[i].push_back(edge(c + dd * 2, 1));
    G[i].push_back(edge(r + dd + 1, 1));
    G[i].push_back(edge(r + dd - 1, 1));
    G[i].push_back(edge(c + dd * 2 + 1, 1));
    G[i].push_back(edge(c + dd * 2 - 1, 1));
    G[r + dd].push_back(edge(i, 0));
    G[c + dd * 2].push_back(edge(i, 0));
    G[r + dd - 1].push_back(edge(i, 0));
    G[r + dd + 1].push_back(edge(i, 0));
    G[c + dd * 2 + 1].push_back(edge(i, 0));
    G[c + dd * 2 - 1].push_back(edge(i, 0));
    p[i] = pair<int, int>(r, c);
    mp[p[i]] = i;
  }
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < 4; j++) {
      int x = p[i].first + nx[j];
      int y = p[i].second + ny[j];
      if (mp.find(pair<int, int>(x, y)) != mp.end())
        G[i].push_back(edge(mp[pair<int, int>(x, y)], 0));
    }
  if (mp.find(pair<int, int>(n, m)) == mp.end()) {
    G[n + dd].push_back(edge(k + 1, 0));
    G[m + dd * 2].push_back(edge(k + 1, 0));
  }
  dijkstra(mp[pair<int, int>(1, 1)]);
  int ans;
  if (mp.find(pair<int, int>(n, m)) == mp.end())
    ans = dis[k + 1];
  else
    ans = dis[mp[pair<int, int>(n, m)]];
  if (ans == INF) ans = -1;
  printf("%d\n", ans);
  return 0;
}
