from itertools import*
n,c=map(int,input().split())

l1=[]
l2=[]
l3=[]
tmp=0
for i in range(n):
    x,v=map(int,input().split())
    l1+=[(x,v+tmp)]
    l2+=[c-x]
    l3.append(v)
    tmp+=v


l3=list(zip(l2[::-1],accumulate(l3[::-1])))[::-1]
ll=list(map(lambda x:x[1]-x[0],l3))
lr=list(map(lambda x:x[1]-x[0],l1))
#print(l3,l1)
#print(ll,lr)
ans=0
for i in range(n):
    c=max(ll[i:]+[0])
    d=max(lr[:i]+[0])
    if c+d>ans:
        ans=c+d
        tmp=i
x=max(lr[:tmp]+[0])
y=max(ll[tmp:]+[0])
if x==0 or y==0:
    print(ans)
else:
    print(ans-min(l1[lr.index(x)][0],l3[ll.index(y)][0]))
#print(min(l1[lr.index(max(lr[:tmp]+[0]))][0],l3[ll.index(max(ll[tmp:]+[0]))][0]))
#print(tmp)
