#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
struct A {
	ll a/*??????*/, b/*??????*/, c/*???????????????(vector)*/;
};
struct P {
	ll a/*???*/, i/*???*/, j/*??????*/, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
vector<A>a[2][100100];
ll b[400100], inf = 999999999999999999;
int main() {
	ll h, w, k;
	cin >> w >> h >> k;
	for (ll i = 0; i < k*2; i+=2) {
		ll x, y;
		cin >> x >> y;
		a[0][x].push_back(A{ y,i,(ll)a[1][y].size() });
		a[1][y].push_back(A{ x,i + 1,(ll)a[0][x].size() - 1 });
	}
	a[0][1].push_back(A{ 1,k*2,(ll)a[1][1].size() });
	a[0][w].push_back(A{ h,k*2 + 1,(ll)a[1][h].size() });
	a[1][h].push_back(A{ w,k*2 + 2,(ll)a[0][w].size() - 1 });
	fill(b, b + k * 2 + 100, inf);
	priority_queue<P, vector<P>, greater<P>>p;
	b[k*2] = 0;
	p.push(P{ 0,1,(ll)a[0][1].size() - 1,0 });
	while (!p.empty()) {
		P t = p.top(); p.pop();
		int c, d;
		if (t.a == 0) {
			c = 0;
			d = 1;
		}
		else {
			c = 1;
			d = 0;
		}
		for (ll i = 0; i < a[c][t.i].size(); i++) {
			ll res = abs(a[c][t.i][t.j].a - a[c][t.i][i].a);
			if (res + t.cost < b[a[c][t.i][i].b]) {
				b[a[c][t.i][i].b] = res + t.cost;
			}
			if (a[c][t.i][i].b!=k*2&&b[a[d][a[c][t.i][i].a][a[c][t.i][i].c].b] > t.cost + res + 1) {
				b[a[d][a[c][t.i][i].a][a[c][t.i][i].c].b] = t.cost + res + 1;
				p.push(P{ d, a[c][t.i][i].a, a[c][t.i][i].c, b[a[d][a[c][t.i][i].a][a[c][t.i][i].c].b] });
			}
		}
	}
	ll ans = min(b[k*2 + 1], b[k*2 + 2]);
	if (ans >= inf) cout << -1 << endl;
	else cout << ans << endl;
}