x = y = 0
ans = 1
for _ in range(int(input())):
    a, b = map(int, input().split())
    ans += max(0, min(a, b) - max(x, y) + (x != y))
    x, y = a, b
print(ans)

9f7d6f869c5e0ef27c77099770e8f5b57bfd7661
<mask token>

<mask token>
for _ in range(int(input())):
    a, b = map(int, input().split())
    ans += max(0, min(a, b) - max(x, y) + (x != y))
    x, y = a, b
print(ans)

x = y = 0
ans = 1
for _ in range(int(input())):
    a, b = map(int, input().split())
    ans += max(0, min(a, b) - max(x, y) + (x != y))
    x, y = a, b
print(ans)
