문제
N, M = map(int, input().split())
standard = []
for i in range(N):
standard.append(list(map(int, input().split())))
test = []
for i in range(M):
test.append(list(map(int, input().split())))
max_speed = 0
i = 0
j = 0
while i < N and j < M:
[section, speed] = standard[i]
[test_section, test_speed] = test[j]
max_speed = max(max_speed, test_speed - speed)
standard[i][0] = section - min(section, test_section)
test[j][0] = test_section - min(section, test_section)
if standard[i][0] > 0 and test[j][0] == 0:
j += 1
elif standard[i][0] == 0 and test[j][0] > 0:
i += 1
else:
i += 1
j += 1
print(max_speed)