#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const long long INF = 9999999999999;
const int EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
class edge{
	public:
	int to;
	ll cost;
	bool type;
	inline edge(){}
	inline edge(int _to,ll _cost,bool _type){
		to = _to;
		cost = _cost;
		type = _type;
	}
	inline bool operator<(const edge &a)const{
		if(cost == a.cost)return to<a.to;
		return a.cost<cost;
	}
};
vector <edge> G[2000001];
ll d[2][2000001];
vector < pair<Pii,int> > switches;
bool start=false;
bool goal=false;
void putEdge(int K,bool type){
	rep(i,K-1){
		if(switches[i].fi.fi == switches[i+1].fi.fi){
			ll dist = switches[i+1].fi.se-switches[i].fi.se;
			G[switches[i].se].PB(edge(switches[i+1].se,dist,type));
			G[switches[i+1].se].PB(edge(switches[i].se,dist,type));
		}
	}
}
ll dijkstra(int K){
	fill(d[0],d[0]+K+10,INF);
	fill(d[1],d[1]+K+10,INF);
	priority_queue < edge > Q;
	Q.push(edge(0,0,0));
	while(!Q.empty()){
		edge e = Q.top();Q.pop();
		if(d[e.type][e.to] != INF)continue;
		d[e.type][e.to] = e.cost;
		rep(i,G[e.to].size()){
			if(e.type == G[e.to][i].type)Q.push(edge(G[e.to][i].to,G[e.to][i].cost+e.cost,e.type));
		}
		if(e.to == 0){
			if(start)Q.push(edge(e.to,e.cost+1,1-e.type));
		}
		else{
			Q.push(edge(e.to,e.cost+1,1-e.type));
		}
	}
	ll ans = min(d[0][K-1],d[1][K-1]);
	if(ans == INF)return -1;
	return ans;
}
int main(){
	int W,H,K;
	scanf("%d%d%d",&W,&H,&K);
	vector< Pii > v;
	rep(i,K){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;b--;
		if(a == 0 && b == 0)start = true;
		if(a == W-1 && b == H-1)goal = true;
		v.PB(Pii(b,a));
	}
	if(!start){
		v.PB(Pii(0,0));
		K++;
	}
	if(!goal){
		v.PB(Pii(H-1,W-1));
		K++;
	}
	sort(v.begin(),v.end());
	rep(i,K){
		switches.PB(mk(v[i],i));
	}
	putEdge(K,1);
	rep(i,K){
		swap(switches[i].fi.fi,switches[i].fi.se);
	}
	sort(switches.begin(),switches.end());
	putEdge(K,0);
	
	printf("%lld\n",dijkstra(K));
	return 0;
}