from collections import deque

n, m = int(eval(input())), int(eval(input()))

B, S = 0, m

d = deque([0]*m)

for _ in range(n):

    cars = list(map(int, input().split()))

    for _ in range(cars[0]): d.append(0)

    try:

        for _ in range(cars[1]): d.pop()

    except IndexError:

        B = 1

    S = max(S, len(d))

print((0 if B else S))
n, m = int(eval(input())), int(eval(input()))

B, S = 0, m

d = [0]*m

for _ in range(n):

    cars = list(map(int, input().split()))

    for _ in range(cars[0]): d.append(0)

    try:

        for _ in range(cars[1]): d.pop()

    except IndexError:

        B = 1

    S = max(S, len(d))

print((0 if B else S))
from collections import deque

n, m = int(eval(input())), int(eval(input()))
B, S = 0, m
d = deque([0] * m)
for _ in range(n):
    cars = list(map(int, input().split()))
    for _ in range(cars[0]):
        d.append(0)
    try:
        for _ in range(cars[1]):
            d.pop()
    except IndexError:
        B = 1
    S = max(S, len(d))
print((0 if B else S))

n, m = int(eval(input())), int(eval(input()))
B, S = 0, m
d = [0] * m
for _ in range(n):
    cars = list(map(int, input().split()))
    for _ in range(cars[0]):
        d.append(0)
    try:
        for _ in range(cars[1]):
            d.pop()
    except IndexError:
        B = 1
    S = max(S, len(d))
print((0 if B else S))

-from collections import deque - -d = deque([0] * m) +d = [0] * m