#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000000;
pair<int, int> gor[10005];
vector<pair<short int, short int> > g[10005];
int put[10005];
deque<int> d;
bool sosedi(pair<int, int> x, pair<int, int> y) {
  if (x.first == y.first && x.second == y.second + 1) return true;
  if (x.first == y.first && x.second == y.second - 1) return true;
  if (x.second == y.second && x.first == y.first + 1) return true;
  if (x.second == y.second && x.first == y.first - 1) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k, uk, toc = -1;
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int r, c;
    cin >> r >> c;
    if (r == n && c == m) toc = i;
    if (r == 1 && c == 1) uk = i;
    gor[i] = make_pair(r, c);
  }
  for (int i = 1; i <= k; i++)
    for (int j = i + 1; j <= k; j++)
      if (sosedi(gor[i], gor[j])) {
        g[i].push_back(make_pair(j, 0));
        g[j].push_back(make_pair(i, 0));
      } else if (gor[i].first == gor[j].first ||
                 gor[i].second == gor[j].second ||
                 gor[i].first == gor[j].first + 1 ||
                 gor[i].second == gor[j].second + 1 ||
                 gor[i].first == gor[j].first - 1 ||
                 gor[i].second == gor[j].second - 1 ||
                 gor[i].first == gor[j].first + 2 ||
                 gor[i].second == gor[j].second + 2 ||
                 gor[i].first == gor[j].first - 2 ||
                 gor[i].second == gor[j].second - 2) {
        g[i].push_back(make_pair(j, 1));
        g[j].push_back(make_pair(i, 1));
      }
  if (toc == -1) {
    for (int i = 1; i <= k; i++)
      if (gor[i].first == n || gor[i].second == m || gor[i].first == n + 1 ||
          gor[i].second == m + 1 || gor[i].first == n - 1 ||
          gor[i].second == m - 1) {
        g[i].push_back(make_pair(k + 1, 1));
        g[k + 1].push_back(make_pair(i, 1));
      }
    toc = k + 1;
  }
  for (int i = 1; i <= k + 1; i++) put[i] = MAXN;
  put[uk] = 0;
  d.push_back(uk);
  while (!d.empty()) {
    int v = d.front();
    d.pop_front();
    for (int i = 0; i < (int)g[v].size(); i++) {
      int to = g[v][i].first;
      int pr = g[v][i].second;
      if (put[to] > put[v] + pr) {
        put[to] = put[v] + pr;
        if (pr == 0)
          d.push_front(to);
        else
          d.push_back(to);
      }
    }
  }
  if (put[toc] == MAXN)
    cout << -1;
  else
    cout << put[toc];
  return 0;
}
