#include <bits/stdc++.h>
using namespace std;
int dist[20200], r[20200], c[20200], n, m, k;
int vis[20200];
const int inf = 1e9;
int main() {
  scanf("%d %d %d", &n, &m, &k);
  bool fg = true;
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", &r[i], &c[i]);
    if (r[i] == n && c[i] == m) fg = false;
    dist[i] = inf;
  }
  r[0] = 1, c[0] = 1;
  if (fg)
    r[k + 1] = n + 1, c[k + 1] = m + 1;
  else
    r[k + 1] = n, c[k + 1] = m;
  dist[k + 1] = inf;
  dist[0] = 0;
  for (int step = 0; step <= k + 1; step++) {
    int id = k + 1;
    for (int i = 0; i <= k; i++)
      if (!vis[i]) {
        if (dist[id] > dist[i]) id = i;
      }
    if (id == k + 1) break;
    vis[id] = 1;
    for (int i = 0; i <= k + 1; i++)
      if (!vis[i]) {
        if (abs(r[i] - r[id]) + abs(c[i] - c[id]) <= 1) {
          dist[i] = dist[id];
        } else if (abs(r[i] - r[id]) <= 2 || abs(c[i] - c[id]) <= 2) {
          if (dist[i] > dist[id]) dist[i] = dist[id] + 1;
        }
      }
  }
  if (dist[k + 1] == inf) {
    puts("-1");
    return 0;
  } else
    printf("%d\n", dist[k + 1]);
}
