#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    ios::sync_with_stdio(false);

    int M,N,K;
    cin >> M >> N >> K;
    vector<pair<int,int> > XY[100001], YX[100001], p;
    vector<LL> c[2];
    p.push_back(MP(1, 1));
    XY[1].push_back(MP(1, 0));
    YX[1].push_back(MP(1, 0));
    c[0].push_back(0);
    c[1].push_back(LL_MAX);
    for(int i=1; i<=K; i++){
        int x,y;
        cin >> x >> y;
        p.push_back(MP(x, y));
        XY[x].push_back(MP(y, i));
        YX[y].push_back(MP(x, i));
        c[0].push_back(LL_MAX);
        c[1].push_back(LL_MAX);
    }
    p.push_back(MP(M, N));
    XY[M].push_back(MP(N, K+1));
    YX[N].push_back(MP(M, K+1));
    c[0].push_back(LL_MAX);
    c[1].push_back(LL_MAX);
    for(int i=1; i<=M; i++) sort(XY[i].begin(), XY[i].end());
    for(int i=1; i<=N; i++) sort(YX[i].begin(), YX[i].end());

    priority_queue<pair<LL, pair<int, int> > > que;
    que.push(MP(LL_MAX, MP(0, 0)));
    while(!que.empty()){
        int now = que.top().second.first;
        int state = que.top().second.second;
        //cout << now << " " << state << " " << LL_MAX-que.top().first << endl;
        que.pop();

        if(now != 0 && now != K+1 && c[(state+1)%2][now] > c[state][now]+1){
            c[(state+1)%2][now] = c[state][now]+1;
            que.push(MP(LL_MAX-c[(state+1)%2][now], MP(now, (state+1)%2)));
        }
        if(state == 0){
            auto itr = lower_bound(XY[p[now].first].begin(), XY[p[now].first].end(), MP(p[now].second, now));
            //cout << itr-XY[p[now].first].begin() << endl;
            //if(itr != XY[p[now].first].begin()) cout << c[state][(itr-1)->second] << " " << c[state][now] + abs(p[now].second-((itr-1)->first)) << endl;
            if(itr != XY[p[now].first].begin() && c[state][(itr-1)->second] > c[state][now] + abs(p[now].second-((itr-1)->first))){
                c[state][(itr-1)->second] = c[state][now] + abs(p[now].second-((itr-1)->first));
                que.push(MP(LL_MAX-c[state][(itr-1)->second], MP((itr-1)->second, state)));
            }
            //if(itr != XY[p[now].first].end()-1) cout << c[state][(itr+1)->second] << " " << c[state][now] + abs(p[now].second-((itr+1)->first)) << endl;
            if(itr != XY[p[now].first].end()-1 && c[state][(itr+1)->second] > c[state][now] + abs(p[now].second-((itr+1)->first))){
                c[state][(itr+1)->second] = c[state][now] + abs(p[now].second-((itr+1)->first));
                que.push(MP(LL_MAX-c[state][(itr+1)->second], MP((itr+1)->second, state)));
            }
        }
        else{
            auto itr = lower_bound(YX[p[now].second].begin(), YX[p[now].second].end(), MP(p[now].first, now));
            if(itr != YX[p[now].second].begin() && c[state][(itr-1)->second] > c[state][now] + abs(p[now].first-((itr-1)->first))){
                c[state][(itr-1)->second] = c[state][now] + abs(p[now].first-((itr-1)->first));
                que.push(MP(LL_MAX-c[state][(itr-1)->second], MP((itr-1)->second, state)));
            }
            if(itr != YX[p[now].second].end()-1 && c[state][(itr+1)->second] > c[state][now] + abs(p[now].first-((itr+1)->first))){
                c[state][(itr+1)->second] = c[state][now] + abs(p[now].first-((itr+1)->first));
                que.push(MP(LL_MAX-c[state][(itr+1)->second], MP((itr+1)->second, state)));
            }
        }
        
    }
    
    if(min(c[0][K+1], c[1][K+1]) == LL_MAX) cout << -1 << endl;
    else cout << min(c[0][K+1], c[1][K+1]) << endl;

    return 0;
}


Measured memory_bytes: 20660