N,C = map(int, input().split())
dis = []
cal = []
for i in range(N):
    x,v = map(int, input().split())
    dis.append(x)
    cal.append(v)
r = [(cal[0] - dis[0])]
for i in range(N-1):
    r.append(r[i] + dis[i] + cal[i+1] - dis[i+1])
l = [(cal[-1] - (C - dis[-1]))]
for i in range(N-1):
    l.append(l[i] - dis[-i-1] + cal[-i-2] + dis[-i-2])
r2 = [0]
l2 = [0]
for i in range(N):
    r2.append(r[i] - dis[i])
    l2.append(l[i] - (C - dis[-i-1]))
r3 = []
l3 = []
for i in range(N-1):
    r3.append(r[i] + max(l2[:-i-1]))
    l3.append(l[i] + max(r2[:-i-1]))
print(max(max(r3),max(l3)))