h,w,n=map(int,input().split()) o=[tuple(map(int,input().split())) for i in range(n)] e=[[] for i in range(n+2)] for i in range(n): a,b,c,d=o[i] e[n]+=[(i,abs(a-1)+abs(b-1))] e[i]+=[(n+1,abs(h-c)+abs(w-d))] for j in range(n): if i!=j: a2,b2,c2,d2=o[j] e[i]+=[(j,abs(c-a2)+abs(d-b2))] v=[h+w-2]*(n+2) v[n]=0 q=[] from heapq import heappush,heappop heappush(q,(0,n)) while len(q)>0: sc,sp=heappop(q) if sc>v[sp]: continue for tp,tc in e[sp]: if v[tp]>sc+tc: v[tp]=sc+tc heappush(q,(v[tp],tp)) print(v[n+1])