import heapq def f(s, n, edge): dist = [float("Inf")]*n dist[s] = 0 hq = [[0,s]] heapq.heapify(hq) while len(hq) > 0: d,i = heapq.heappop(hq) if dist[i] < d: continue for j,d_1 in edge[i]: if dist[j] > (dist[i] + d_1): dist[j] = dist[i] + d_1 heapq.heappush(hq, [dist[j],j]) return dist H,W,N = map(int,input().split()) s = 0 g = 2*N + 1 G = [[] for i in range(2*N+2)] G[s].append((g,H+W-2)) for i in range(1,N+1): a,b,c,d = map(int,input().split()) u,v = i,i+N G[0].append((u,a+b-2)) G[u].append((v,1)) G[v].append((g,H+W-c-d)) dist = f(0,2*N+2,G) print(dist[g])