import sys input = sys.stdin.readline from operator import itemgetter H,W,N=map(int,input().split()) WA=[list(map(int,input().split())) for i in range(N)] WA=[[1,1,1,1]]+WA+[[H,W,H,W]] DP=[1<<63]*len(WA) WA.sort(key=itemgetter(0)) WA.sort(key=itemgetter(1)) DP[0]=0 for i in range(len(WA)): now=DP[i] a,b,c,d=WA[i] for j in range(len(WA)): e,f,g,h=WA[j] if a<=e and b<=f: dis=(e-a)+(f-b) DP[j]=min(DP[j],DP[i]+dis) if c<=e and d<=f: dis=(e-c)+(f-d) DP[j]=min(DP[j],DP[i]+dis+1) print(DP[-1])