nc = list(map(int,input().split()))
xv = []
for i in range(nc[0]):
    xv.append(list(map(int, input().split())))

cal1 = [xv[0][1] - xv[0][0]]
for i in range(1, nc[0]):
    cal1.append(cal1[i - 1] + xv[i][1] - (xv[i][0] - xv[i - 1][0]))
cal1 = max(cal1)

cal2 = [xv[-1][1] - (nc[1] - xv[-1][0])]
for i in range(1, nc[0]):
    cal2.append(cal2[i - 1] + xv[nc[0] - i - 1][1] - (xv[nc[0] - i][0] - xv[nc[0] - i - 1][0]))
cal2 = max(cal2)

cal3 = [[0 for i in range(nc[0])] for j in range(nc[0])]
cal_r = [0]
for i in range(nc[0]):
    cal_r.append(cal_r[i] + xv[i][1])
cal_l = [0]
for i in range(nc[0]):
    cal_l.append(cal_l[i] + xv[- i - 1][1])
for i in range(nc[0]):
    for j in range(nc[0] - i - 1):
        cal3[i][j] = cal_r[i + 1] + cal_l[j + 1] - xv[i][0] * 2 - (nc[1] - xv[- j - 1][0])
cal3 = max(max(i) for i in cal3)

cal4 = [[0 for i in range(nc[0])] for j in range(nc[0])]
for i in range(nc[0]):
    for j in range(nc[0] - i - 1):
        cal4[i][j] = cal_l[i + 1]+ cal_r[j + 1] - (nc[1] - xv[- i - 1][0]) * 2 - xv[j][0]
cal4 = max(max(i) for i in cal4)
cal = max(cal1, cal2, cal3, cal4, 0)
print(cal)