# -*- coding: utf-8 -*-

line = input().split(" ")
n = int(line[0])
c = int(line[1])

sushi = []
for _ in range(n):
    line = input().split(" ")
    sushi.append([int(line[0]), int(line[1])]) #[x,v]

ret = 0

r1 = []
r2 = []
state = 0
for i in range(n):
    s = sushi[i]
    state += s[1]
    r1.append(state-2*s[0])
    r2.append(state-s[0])
    if state-s[0]>ret:
        ret = state-s[0]

l1 = []
l2 = []
state = 0
for i in range(n-1,-1,-1):
    s = sushi[i]
    state += s[1]
    l1.append(state-2*(c-s[0]))
    l2.append(state-(c-s[0]))
    if state-(c-s[0])>ret:
        ret = state-(c-s[0])

for (i,r) in enumerate(r1):
    for (j,l) in enumerate(l2):
        if i+j+2>n:
            continue
        if r+l>ret:
            ret = r+l

for (i,l) in enumerate(l1):
    for (j,r) in enumerate(r2):
        if i+j+2>n:
            continue
        if r+l>ret:
            ret = r+l


print(ret)
