import heapq from collections import defaultdict H,W,N=map(int,input().split()) ABCD=[tuple(map(int,input().split())) for _ in range(N)] dist=defaultdict(int) pos=(1,1) dist[pos]=0 Q=[] heapq.heapify(Q) heapq.heappush(Q,(dist[pos],pos)) while len(Q): e,(i,j)=heapq.heappop(Q) for (a,b,c,d) in ABCD: if (i,j)==(a,b): if dist.get((c,d)) is None or e+1