h, w, n = map(int, input().split()) V = [0, h * w - 1] edges = {} for _ in range(n): a, b, c, d = map(int, input().split()) a -= 1 b -= 1 c -= 1 d -= 1 x = a * w + b y = c * w + d V.append(x) V.append(y) edges.setdefault(x, []).append(y) V = sorted(set(V)) idx = {v: i for i, v in enumerate(V)} n = len(V) dist = [1 << 60] * n dist[0] = 0 used = [False] * n for _ in range(n): pos = -1 mi = 1 << 60 for i in range(n): if not used[i] and dist[i] < mi: mi = dist[i] pos = i used[pos] = True i1 = V[pos] // w j1 = V[pos] - w * i1 for npos in range(n): i2 = V[npos] // w j2 = V[npos] - w * i2 nd = dist[pos] + abs(i1 - i2) + abs(j1 - j2) dist[npos] = min(dist[npos], nd) for npos in edges.get(V[pos], []): nd = dist[pos] + 1 dist[idx[npos]] = min(dist[idx[npos]], nd) print(dist[-1])