#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
template <class S, class T>
istream& operator>>(istream& is, pair<S, T>& p) {
  return is >> p.first >> p.second;
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << p.first << " " << p.second;
}
template <class T>
void maxi(T& x, T y) {
  if (x < y) x = y;
}
template <class T>
void mini(T& x, T y) {
  if (x > y) x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const int INF = 1e9;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
struct Edge {
  int to, cost;
  Edge(int t, int c = 0) : to(t), cost(c) {}
  bool operator>(const Edge& rhs) const { return cost > rhs.cost; }
  bool operator<(const Edge& rhs) const { return cost < rhs.cost; }
};
void Dijkstra(const vector<vector<Edge> >& edges, vector<int>& d, int s) {
  using Type = PII;
  priority_queue<Type, vector<Type>, greater<Type> > pq;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    Type pii = pq.top();
    pq.pop();
    int v = pii.second;
    if (d[v] < pii.first) continue;
    for (unsigned int i = 0; i < edges[v].size(); ++i) {
      const Edge& e = edges[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        pq.push(make_pair(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int H, W, K;
  cin >> H >> W >> K;
  int V = H + W + K + 10;
  vector<vector<Edge> > G(V);
  int S = V - 1;
  int T = V - 2;
  map<PII, int> ps;
  for (int i = (0); i < (K); ++i) {
    int y, x;
    cin >> y >> x;
    --y;
    --x;
    ps[make_pair(y, x)] = i;
    if (x + y == 0) S = H + W + i;
    for (int ty = max(0, y - 1); ty <= min(H - 1, y + 1); ++ty) {
      G[H + W + i].emplace_back(ty, 1);
      G[ty].emplace_back(H + W + i, 0);
    }
    for (int tx = max(0, x - 1); tx <= min(W - 1, x + 1); ++tx) {
      G[H + W + i].emplace_back(H + tx, 1);
      G[H + tx].emplace_back(H + W + i, 0);
    }
    if (x == W - 1 && y == H - 1) {
      G[H + W + i].emplace_back(T, 0);
    }
  }
  for (auto&& p : ps) {
    for (int d = (0); d < (4); ++d) {
      PII np(p.first.first + dy[d], p.first.second + dx[d]);
      if (!ps.count(np)) continue;
      int to = ps[np];
      G[H + W + p.second].emplace_back(H + W + to, 0);
    }
  }
  G[H - 1].emplace_back(T, 0);
  G[H + W - 1].emplace_back(T, 0);
  VI dist(V);
  Dijkstra(G, dist, S);
  cout << (dist[T] == INF ? -1 : dist[T]) << endl;
  return 0;
}
