n, c = map(int, input().split())
xv = [[int(x) for x in input().split()] for _ in range(n)]
n += 1
xv.insert(0, [0, 0])
maxcal = 0

for i in range(n):
    for j in range(n):
        cal = 0
        d = 0
        for k in range(0, i + 1):
            cal += xv[k][1]
        if i != j:
            for k in range(j, n):
                cal += xv[k][1]
            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)
