#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
vector<vector<long long>> v1, v2;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, k;
  cin >> n >> m >> k;
  long long ans[k + 1];
  v1.resize(n + 5);
  v2.resize(m + 5);
  memset(ans, -1, sizeof(ans));
  map<pair<long long, long long>, long long> m1;
  long long l = 0;
  while (k--) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    m1[{x, y}] = l;
    v1[x].push_back(y);
    v2[y].push_back(x);
    l++;
  }
  bool b = false;
  ans[0] = 0;
  deque<pair<long long, long long>> dq;
  dq.push_back({0, 0});
  while (!dq.empty()) {
    auto p = dq.front();
    dq.pop_front();
    for (long long i = 0; i < 4; i++) {
      if (m1.find({p.first + dx[i], p.second + dy[i]}) != m1.end() &&
          (ans[m1[{p.first + dx[i], p.second + dy[i]}]] == -1 ||
           ans[m1[{p.first + dx[i], p.second + dy[i]}]] > ans[m1[p]])) {
        ans[m1[{p.first + dx[i], p.second + dy[i]}]] = ans[m1[p]];
        dq.push_front({p.first + dx[i], p.second + dy[i]});
      }
    }
    for (auto j : v1[p.first]) {
      if (ans[m1[{p.first, j}]] == -1) {
        ans[m1[{p.first, j}]] = ans[m1[p]] + 1;
        dq.push_back({p.first, j});
      }
    }
    for (auto j : v1[p.first + 1]) {
      if (ans[m1[{p.first + 1, j}]] == -1) {
        ans[m1[{p.first + 1, j}]] = ans[m1[p]] + 1;
        dq.push_back({p.first + 1, j});
      }
    }
    for (auto j : v1[p.first + 2]) {
      if (ans[m1[{p.first + 2, j}]] == -1) {
        ans[m1[{p.first + 2, j}]] = ans[m1[p]] + 1;
        dq.push_back({p.first + 2, j});
      }
    }
    if (p.first > 0)
      for (auto j : v1[p.first - 1]) {
        if (ans[m1[{p.first - 1, j}]] == -1) {
          ans[m1[{p.first - 1, j}]] = ans[m1[p]] + 1;
          dq.push_back({p.first - 1, j});
        }
      }
    if (p.first > 1)
      for (auto j : v1[p.first - 2]) {
        if (ans[m1[{p.first - 2, j}]] == -1) {
          ans[m1[{p.first - 2, j}]] = ans[m1[p]] + 1;
          dq.push_back({p.first - 2, j});
        }
      }
    for (auto j : v2[p.second]) {
      if (ans[m1[{j, p.second}]] == -1) {
        ans[m1[{j, p.second}]] = ans[m1[p]] + 1;
        dq.push_back({j, p.second});
      }
    }
    for (auto j : v2[p.second + 1]) {
      if (ans[m1[{j, p.second + 1}]] == -1) {
        ans[m1[{j, p.second + 1}]] = ans[m1[p]] + 1;
        dq.push_back({j, p.second + 1});
      }
    }
    for (auto j : v2[p.second + 2]) {
      if (ans[m1[{j, p.second + 2}]] == -1) {
        ans[m1[{j, p.second + 2}]] = ans[m1[p]] + 1;
        dq.push_back({j, p.second + 2});
      }
    }
    if (p.second > 0)
      for (auto j : v2[p.second - 1]) {
        if (ans[m1[{j, p.second - 1}]] == -1) {
          ans[m1[{j, p.second - 1}]] = ans[m1[p]] + 1;
          dq.push_back({j, p.second - 1});
        }
      }
    if (p.second > 1)
      for (auto j : v2[p.second - 2]) {
        if (ans[m1[{j, p.second - 2}]] == -1) {
          ans[m1[{j, p.second - 2}]] = ans[m1[p]] + 1;
          dq.push_back({j, p.second - 2});
        }
      }
  }
  if (m1.find({n - 1, m - 1}) != m1.end()) {
    if (ans[m1[{n - 1, m - 1}]] == -1) {
      cout << -1;
    } else
      cout << ans[m1[{n - 1, m - 1}]];
  } else {
    long long ans1 = INT_MAX / 2;
    for (auto j : v1[n - 1]) {
      if (ans[m1[{n - 1, j}]] != -1) ans1 = min(ans1, ans[m1[{n - 1, j}]] + 1);
    }
    for (auto j : v1[n - 2]) {
      if (ans[m1[{n - 2, j}]] != -1) ans1 = min(ans1, ans[m1[{n - 2, j}]] + 1);
    }
    for (auto j : v2[m - 1]) {
      if (ans[m1[{j, m - 1}]] != -1) ans1 = min(ans1, ans[m1[{j, m - 1}]] + 1);
    }
    for (auto j : v2[m - 2]) {
      if (ans[m1[{j, m - 2}]] != -1) ans1 = min(ans1, ans[m1[{j, m - 2}]] + 1);
    }
    if (ans1 > INT_MAX / 4)
      cout << -1;
    else
      cout << ans1;
  }
  return 0;
}
