#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  bool dest_is_lit = false;
  int m, n, k;
  int start_index, dest_index;
  scanf("%d %d %d", &n, &m, &k);
  pair<int, int> lights[k + 1];
  unsigned mindis[k + 1];
  bool visit_pending[k + 1];
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &lights[i].first, &lights[i].second);
    mindis[i] = -1;
    visit_pending[i] = false;
    if (lights[i].first == 1 && lights[i].second == 1) start_index = i;
    if (lights[i].first == n && lights[i].second == m) {
      dest_is_lit = true;
      dest_index = i;
    }
  }
  if (!dest_is_lit) {
    lights[k] = make_pair(n + 1, m + 1);
    mindis[k] = -1;
    visit_pending[k] = false;
    dest_index = k;
  }
  const int total_lights = dest_is_lit ? k : k + 1;
  queue<int> search_queue;
  mindis[start_index] = 0;
  search_queue.push(start_index);
  visit_pending[start_index] = true;
  while (!search_queue.empty()) {
    int this_index = search_queue.front();
    visit_pending[this_index] = false;
    search_queue.pop();
    for (int i = 0; i < total_lights; i++) {
      int addition = -1;
      if (abs(lights[this_index].first - lights[i].first) +
              abs(lights[this_index].second - lights[i].second) <=
          1) {
        addition = 0;
      } else if ((abs(lights[this_index].first - lights[i].first) <= 2) ||
                 (abs(lights[this_index].second - lights[i].second) <= 2)) {
        addition = 1;
      }
      if (addition != -1) {
        if (mindis[this_index] + addition < mindis[i]) {
          mindis[i] = mindis[this_index] + addition;
          if (!visit_pending[i]) {
            search_queue.push(i);
            visit_pending[i] = true;
          }
        }
      }
    }
  }
  printf("%d", mindis[dest_index]);
  return 0;
}
