N=int(eval(input()))

sl=[]

for i in range(N):

  sl.append(list(map(int,input().split())))

sl.sort()

sl_table = [True for i in range(len(sl))]



for i in range(N):

  for j in range(min(i+1,N),N):

    if sl[j][0]-sl[i][1]>0:

      break

    sl[i]=[min(min(sl[i]),min(sl[j])),max(max(sl[i]),max(sl[j]))]

    sl_table[j]=False



print((sum((s[1]-s[0]+1)*sl_table[i] for i,s in enumerate(sl))))
N=int(eval(input()))

answer=0

for i in range(N):

  l,r = list(map(int,input().split()))

  answer+=r-l+1

print(answer)
N = int(eval(input()))
sl = []
for i in range(N):
    sl.append(list(map(int, input().split())))
sl.sort()
sl_table = [True for i in range(len(sl))]
for i in range(N):
    for j in range(min(i + 1, N), N):
        if sl[j][0] - sl[i][1] > 0:
            break
        sl[i] = [min(min(sl[i]), min(sl[j])), max(max(sl[i]), max(sl[j]))]
        sl_table[j] = False
print((sum((s[1] - s[0] + 1) * sl_table[i] for i, s in enumerate(sl))))

N = int(eval(input()))
answer = 0
for i in range(N):
    l, r = list(map(int, input().split()))
    answer += r - l + 1
print(answer)

-sl = [] +answer = 0 -    sl.append(list(map(int, input().split()))) -sl.sort() -sl_table = [True for i in range(len(sl))] -for i in range(N): -    for j in range(min(i + 1, N), N): -        if sl[j][0] - sl[i][1] > 0: -            break -        sl[i] = [min(min(sl[i]), min(sl[j])), max(max(sl[i]), max(sl[j]))] -        sl_table[j] = False -print((sum((s[1] - s[0] + 1) * sl_table[i] for i, s in enumerate(sl)))) +    l, r = list(map(int, input().split())) +    answer += r - l + 1 +print(answer)