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

#define pb push_back
const int N = 2e5L + 11;
using ll = long long;
const ll inf = 1e18L;

int x[N], y[N];
vector <int> vx[N], vy[N];
int atx[N], aty[N];
ll dis[N][2];
struct node {
	ll dis; int k1, k2;
	bool operator <(node r) const {
		return tie(dis, k1, k2) < tie(r.dis, r.k1, r.k2);
	}
};

int main() {
	ios :: sync_with_stdio(0);
	int w, h, n; cin >> w >> h >> n;
	for(int i = 1; i <= n; i ++)
		cin >> x[i] >> y[i];
	x[0] = y[0] = 1;
	x[n + 1] = w; y[n + 1] = h;

	for(int i = 0; i <= n + 1; i ++) {
		vx[x[i]].pb(i);
		vy[y[i]].pb(i);
	}
	for(int i = 0; i < N; i ++) {
		sort(vx[i].begin(), vx[i].end(), [&](int i, int j){ return y[i] < y[j]; });
		sort(vy[i].begin(), vy[i].end(), [&](int i, int j){ return x[i] < x[j]; });
		for(int j = 0; j < vx[i].size(); j ++) atx[vx[i][j]] = j;
		for(int j = 0; j < vy[i].size(); j ++) aty[vy[i][j]] = j;
	}

	for(int i = 0; i <= n + 1; i ++)
		for(int j : {0, 1}) dis[i][j] = inf;
	dis[0][0] = 0;
	set <node> st;
	for(int i = 0; i <= n + 1; i ++)
		for(int j : {0, 1}) st.insert({dis[i][j], i, j});

	auto upd = [&](int k1, int k2, ll w) {
		if(dis[k1][k2] > w) {
			st.erase({dis[k1][k2], k1, k2});
			dis[k1][k2] = w;
			st.insert({dis[k1][k2], k1, k2});
		}
	};
	auto f = [&](int i, int j) {
		return abs(x[i] - x[j]) + abs(y[i] - y[j]);
	};
	auto solve = [&](vector <int> &v, int k1, int k2) {
		int i = (k2 == 0) ? atx[k1] : aty[k1];
		if(i > 0) upd(v[i - 1], k2, f(v[i], v[i - 1]) + dis[k1][k2]);
		if(i + 1 < v.size()) upd(v[i + 1], k2, f(v[i], v[i + 1]) + dis[k1][k2]);
	};
	while(!st.empty()) {
		node i = *st.begin(); st.erase(st.begin());
		//cout << i.dis << ' ' << i.k1 << ' ' << i.k2 << '\n';
		if(i.k1 >= 1 && i.k1 <= n) upd(i.k1, i.k2 ^ 1, i.dis + 1);
		if(i.k2 == 0) solve(vx[x[i.k1]], i.k1, i.k2);
		if(i.k2 == 1) solve(vy[y[i.k1]], i.k1, i.k2);
	}
	ll ans = min(dis[n + 1][0], dis[n + 1][1]);
	cout << ((ans == inf) ? -1 : ans) << '\n';
}