from heapq import heapify, heappop, heappush H, W, N = map(int, input().split()) G = [[] for _ in range(2 * N + 2)] G[0].append((2 * N + 1, H - 1 + W - 1)) P = [] for _ in range(N): a, b, c, d = map(int, input().split()) a -= 1; b -= 1; c -= 1; d -= 1 P.append((a, b, c, d)) for i, (a, b, c, d) in enumerate(P): G[0].append((2 * i + 1, a + b)) G[2 * i + 1].append((2 * i + 2, 1)) G[2 * i + 2].append((2 * N + 1, H - 1 - c + W - 1 - d)) for j, (e, f, g, h) in enumerate(P): if a == e and b == f: continue G[2 * i + 2].append((2 * j + 1, abs(c - e) + abs(d - f))) dist = [10 ** 18] * (2 * N + 2) dist[0] = 0 pq = [(0, 0)] heapify(pq) while len(pq) > 0: d, u = heappop(pq) for v, c in G[u]: if dist[v] > dist[u] + c: dist[v] = dist[u] + c heappush(pq, (dist[v], v)) print(dist[2 *N + 1])