#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

#define INF (1LL<<60)
typedef pair<int, int> P;

int M, N, K;
P T[200010];
long long D[200010];
vector<int> xs[100010], ys[100010];

int main() {
  cin >> M >> N >> K;

  T[0] = P(M, N);
  xs[M].push_back(0);
  ys[N].push_back(0);

  for (int i=1; i<K+1; i++) {
    int x, y;
    cin >> x >> y;
    T[i] = P(x, y);
    if (x != M || y != N) {
      xs[x].push_back(i);
      ys[y].push_back(i);
    }
  }

  for (int i=0; i<K+1; i++) D[i] = INF;

  queue<P> q;
  for (int i : xs[1]) {
    D[i] = T[i].second - 1;
    q.push(P(i, 0));
  }

  while (!q.empty()) {
    int s = q.front().first, d = q.front().second; q.pop();
    P p = T[s];

    if (d == 1) {
      for (int i : xs[p.first]) {
        if (i == s) continue;
        P t = T[i];
        long long l = abs(t.second - p.second) + 1LL;
        if (D[i] > D[s] + l) {
          D[i] = D[s] + l;
          q.push(P(i, 0));
        }
      }
    }
    else {
      for (int i : ys[p.second]) {
        if (i == s) continue;
        P t = T[i];
        long long l = abs(t.first - p.first) + 1LL;
        if (D[i] > D[s] + l) {
          D[i] = D[s] + l;
          q.push(P(i, 1));
        }
      }
    }
  }

  cout << (D[0] != INF ? D[0] : -1) << "\n";
  return 0;
}