H,W,N=map(int,input().split()) from collections import defaultdict,deque G=defaultdict(defaultdict) C=defaultdict(int) I=[] O=[] G[(1,1)][(H,W)]=H-1+W-1 for _ in range(N): a,b,c,d=map(int,input().split()) G[(1,1)][(a,b)]=a-1+b-1 G[(1,1)][(c,d)]=c-1+d-1 G[(a,b)][(c,d)]=1 G[(a,b)][(H,W)]=H-a+H-b G[(c,d)][(H,W)]=H-c+W-d C[(a,b)]=1<<60 C[(c,d)]=1<<60 I.append((a,b)) O.append((c,d)) for c,d in O: for a,b in I: G[(c,d)][(a,b)]=abs(c-a)+abs(d-b) G[(a,b)][(c,d)]=abs(c-a)+abs(d-b) C[(H,W)]=1<<60 C[(1,1)]=0 Q=deque() Q.append((1,1)) while Q: a,b=Q.popleft() for c,d in G[(a,b)].keys(): tmp=C[(a,b)]+G[(a,b)][(c,d)] if tmp