tmp = list(map(int, input().split()))
n,c = tmp[0],tmp[1]
xs, vs = [0],[]
ans = [0]
for i in range(n):
    tmp = list(map(int, input().split()))
    xs.append(tmp[0])
    vs.append(tmp[1])
xs_rev, vs_rev = [0],[]
for i in range(n):
    xs_rev.append(c-xs[-(i+1)])
    vs_rev.append(vs[-(i+1)])
def findmax(v_data,x_data,m,mode = True):
    vs1 = [0]
    for i in range(m):
        if mode:
            vs1.append(vs1[-1] + v_data[i] - x_data[i+1] + x_data[i])
        else:
            vs1.append(vs1[-1] + v_data[i] - x_data[i+1] * 2 + x_data[i] * 2)
    return(max(vs1))
ans.append(findmax(vs,xs,n))
ans.append(findmax(vs_rev,xs_rev,n))
sumv = []
for i in range(0,n):
    sumv.append(findmax(vs[:i],xs[:i+1],i) + findmax(vs_rev[:n-i],xs_rev[:n-i+1],n-i,mode = False))
if sumv != []:
    ans.append(max(sumv))
sumv = []
for i in range(0,n):
    sumv.append(findmax(vs[:i],xs[:i+1],i,mode = False) + findmax(vs_rev[:n-i],xs_rev[:n-i+1],n-i))
if sumv != []:
    ans.append(max(sumv))
print(max(ans))
