import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd h,w,n = map(int,input().split()) za = [list(map(int,input().split())) for i in range(n)] graph = [[] for i in range(n+3)] for i in range(n): ai,bi,ci,di = za[i] for j in range(n): if i == j: continue aj,bj,cj,dj = za[j] dis = abs(ci-aj) + abs(di-bj) graph[i].append((j, dis+1)) graph[j].append((i, dis+1)) graph[n].append((i, ai+bi-2)) graph[i].append((n+1, abs(h-ci)+abs(w-di))) #ダイクストラ法 def dijkstra(s,n): # sがスタート、nが頂点数 INF = 10**15 dist = [INF]*(n+1) que = [(0,s)] dist[s] = 0 while que: c,crr = heappop(que) if c > dist[crr]: continue for nxt, cost in graph[crr]: if dist[crr] + cost < dist[nxt]: dist[nxt] = dist[crr] + cost heappush(que,(dist[nxt],nxt)) return dist d = dijkstra(n,n+2) print(min(d[n+1]+1, h+w-2))