n, c = map(int, input().split())
sushi = []
for i in range(n):
    x, v = map(int, input().split())
    sushi.append((x, v))
sushi.sort()
sushi_reversed = list(reversed([(c - x, v) for x, v in sushi]))


# def solve(s, sr):
#     d = 0
#     v = 0
#     v_d_max = (0, 0)
#     v_2d_max = (0, 0)
#     conds = []

#     for x_i, v_i in s:
#         v = v + v_i - (x_i - d)
#         d = x_i
#         v_d_max = max(v_d_max, (v, d))
#         if v - d > v_2d_max[0]:
#             v_2d_max = (v - d, d)
#             conds.append((v - d, d))
#     return v_d_max, v_2d_max, conds

def solve(s, sr):
    d = 0
    v = 0
    v_2d_max = 0
    v_max = 0
    n = len(s)
    for i in range(n):
        x_i, v_i = s[i]
        v = v + v_i - (x_i - d)
        d = x_i
        v_max = max(v_max, v)
        if v - d > v_2d_max:
            v_2d_max = v - d
            v_sub = sub_solve(sr[:n - 1 - i])
            v_max = max(v_max, v_2d_max + v_sub)
    return v_max


def sub_solve(s):
    d = 0
    v = 0
    v_max = 0

    for x_i, v_i in s:
        v = v + v_i - (x_i - d)
        d = x_i
        v_max = max(v_max, v)
    return v_max

# l_v_d_max, l_v_2d_max, l_conds = solve(sushi, sushi_reversed)
# r_v_d_max, r_v_2d_max, r_conds = solve(sushi_reversed, sushi)
# print(l_v_d_max, l_v_2d_max, l_conds, r_v_d_max, r_v_2d_max, r_conds)

# max_v = max(l_v_d_max[0], r_v_d_max[0])
# if l_v_d_max[1] + r_v_2d_max[1] < c:
#     max_v = max(max_v, l_v_d_max[0] + r_v_2d_max[0])
# else:
#     for v, d in r_conds:
#         if l_v_d_max[1] + d < c:
#             max_v = max(max_v, l_v_d_max[0] + v)

# if l_v_2d_max[1] + r_v_d_max[1] < c:
#     max_v = max(max_v, l_v_2d_max[0] + r_v_d_max[0])
# else:
#     for v, d in l_conds:
#         if d + r_v_d_max[1] < c:
#             max_v = max(max_v, v + r_v_d_max[0])

# print(max_v)

# l_v_d_max, l_v_2d_max, l_conds = solve(sushi, sushi_reversed)
# r_v_d_max, r_v_2d_max, r_conds = solve(sushi_reversed, sushi)
# print(max_v)


l = solve(sushi, sushi_reversed)
r = solve(sushi_reversed, sushi)
print(max(solve(sushi, sushi_reversed), solve(sushi_reversed, sushi)))
