# 根本不用動態規劃
N,M=map(int,input().split())L=[]for i in range(N+M): L.append([int(x) for x in input().split()])L=sorted(L, key=lambda x:x[0]-x[1])[::-1]S=0i=0while i<M: S+=L[i][1] i+=1while i<M+N: S+=L[i][0] i+=1print(S)