#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define int long long

const int inf = 1e18 + 9;

typedef pair<int, int> P;
typedef pair<int, P> PP;

struct edge
{
  edge() {}
  edge (int t, int v, int c) { to = t; f = v; cost = c; }
  int to, f, cost;
};

int h, w, k;
vector<PP> a, b;
vector<edge> G[2][202020];
int d[2][202020];

void dijkstra(int s, int po)
{
  for (int i = 0; i < 202020; i++){
    d[0][i] = d[1][i] = inf;
  }
  priority_queue<PP, vector<PP>, greater<PP> > q;

  d[0][s] = 0;
  q.push(PP(0, P(s, 0)));

  while (!q.empty()){
    PP p = q.top(); q.pop();
    int v = p.se.fi;
    int f = p.se.se;

    if (p.fi > d[f][v]) continue;
    for (int i = 0; i < G[f][v].size(); i++){
      edge e = G[f][v][i];
      if (d[e.f][e.to] > d[f][v] + e.cost){
        d[e.f][e.to] = d[f][v] + e.cost;
        q.push(PP(d[e.f][e.to], P(e.to, e.f)));
      }
    }
  }
}

signed main()
{
  bool izryt = false, _izryt = false;
  cin >> w >> h >> k;
  for (int i = 1; i <= k; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    if (x == 0 && y == 0){
      a.push_back(PP(x, P(y, 0)));
      b.push_back(PP(y, P(x, 0)));
      G[0][0].push_back(edge(0, 1, 1));
      G[1][0].push_back(edge(0, 0, 1));
      izryt = true;
    }
    else if (x + 1 == w && y + 1 == h){
      a.push_back(PP(x, P(y, k + 1)));
      b.push_back(PP(y, P(x, k + 1)));
      G[0][k + 1].push_back(edge(k + 1, 1, 1));
      G[1][k + 1].push_back(edge(k + 1, 0, 1));
      _izryt = true;
    }
    else {
      a.push_back(PP(x, P(y, i)));
      b.push_back(PP(y, P(x, i)));
      G[0][i].push_back(edge(i, 1, 1));
      G[1][i].push_back(edge(i, 0, 1));
    }
  }

  if (!izryt) a.push_back(PP(0, P(0, 0)));
  if (!_izryt){
    a.push_back(PP(w - 1, P(h - 1, k + 1)));
    b.push_back(PP(h - 1, P(w - 1, k + 1)));
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  for (int i = 0; i < a.size() - 1; i++){
    if (a[i].fi == a[i + 1].fi && a[i].se.fi != a[i + 1].se.fi){
      G[0][a[i].se.se].push_back(edge(a[i + 1].se.se, 0, abs(a[i].se.fi - a[i + 1].se.fi)));
      G[0][a[i + 1].se.se].push_back(edge(a[i].se.se, 0, abs(a[i].se.fi - a[i + 1].se.fi)));
    }
  }

  for (int i = 0; i < b.size() - 1; i++){
    if (b[i].fi == b[i + 1].fi && b[i].se.fi != b[i + 1].se.fi){
      G[1][b[i].se.se].push_back(edge(b[i + 1].se.se, 1, abs(b[i].se.fi - b[i + 1].se.fi)));
      G[1][b[i + 1].se.se].push_back(edge(b[i].se.se, 1, abs(b[i].se.fi - b[i + 1].se.fi)));
    }
  }

  dijkstra(0, 0);

  int ans = min(d[0][k + 1], d[1][k + 1]);
  cout << (ans == inf ? -1 : ans) << endl;
}