n = int(eval(input()))

m = int(eval(input()))

S_max = m

for i in range(n):

    a, b = list(map(int, input().split()))

    m += a - b

    if m < 0:

        print((0))

        break

    S_max = max(S_max, m)

else:

    print(S_max)

n = int(eval(input()))

m = int(eval(input()))

S_max = m

for i in range(n):

    a, b = list(map(int, input().split()))

    m += a - b

    if m < 0:

        S_max = 0

        break

    S_max = max(S_max, m)

print(S_max)

n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
    a, b = list(map(int, input().split()))
    m += a - b
    if m < 0:
        print((0))
        break
    S_max = max(S_max, m)
else:
    print(S_max)

n = int(eval(input()))
m = int(eval(input()))
S_max = m
for i in range(n):
    a, b = list(map(int, input().split()))
    m += a - b
    if m < 0:
        S_max = 0
        break
    S_max = max(S_max, m)
print(S_max)

-        print((0)) +        S_max = 0 -else: -    print(S_max) +print(S_max)