n, c = map(int, input().split())
xv = [[int(x) for x in input().split()] for _ in range(n)]
n += 1
oa = [0] * n
ob = [0] * n
xv.insert(0, [0, 0])
maxcal = 0
for i in range(1,n):
    oa[i] = oa[i-1] + xv[i][1]
ob[n-1] = xv[i][1]
for i in reversed(range(0,n-1)):
    ob[i] = xv[i][1] + ob[i+1]
for i in range(n):
    for j in range(n):
        cal = oa[i]
        d = 0
        if i != j:
            cal += ob[j]
            d = xv[i][0] * 2 + (c - xv[j][0])
            d2 = xv[i][0] + (c - xv[j][0]) * 2
            d = min(d, d2)
        else:
            d = xv[i][0]
        if d < c:
            maxcal = max(maxcal, cal - d)
print(maxcal)
