H,W,N=map(int,input().split()) result=H-1+W-1 from heapq import heappush,heappop L=[] for i in range(N): x,y,c,d=map(int,input().split()) L.append((x,y,c,d)) kaku=[False]*N dist=[10**15]*N S=[] for i in range(N): x,y=L[i][0],L[i][1] dist[i]=abs(x-1)+abs(y-1) heappush(S,dist[i]*10**10+i) while S: w=heappop(S) time=w//(10**10) pos=w%(10**10) if kaku[pos]==True: continue kaku[pos]=True c,d=L[pos][2],L[pos][3] for j in range(N): if kaku[j]==True: continue x,y=L[j][0],L[j][1] di=abs(x-c)+abs(y-d) if dist[j]>dist[pos]+di+1: dist[j]=dist[pos]+di+1 heappush(S,dist[j]*10**10+j) for i in range(N): c,d=L[i][2],L[i][3] di=abs(c-H)+abs(d-W) result=min(result,dist[i]+di+1) print(result)