N,C = map(int,input().split())
table=[]
for i in range(N):
    x,v=map(int,input().split())
    table.append([x,v])
V=[0]*N
V[0]=table[0][1]
for i in range(1,N):
    V[i]=V[i-1]+table[i][1]
ans=0
clo_1=0
clo_2=0
rclo_1=0
rclo_2=0
for i in range(N):
    #print(V[i]-table[i][0])
    ans=max(ans,V[i]-table[i][0])
    if table[i][0]<=C//2:
        #print(V[i]-table[i][0])
        #print(V[i]-2*table[i][0])
        clo_1 = max(clo_1,V[i]-table[i][0])
        clo_2 = max(clo_2,V[i]-2*table[i][0])
for i in range(N-1,0,-1):
    #print(V[N-1]-V[i-1]-C+table[i][0])
    ans = max(ans,V[N-1]-V[i-1]-C+table[i][0])
    if table[i][0]>C//2 and i!=0:
        #print(V[N-1]-V[i-1]-C+table[i][0])
        #print(V[N-1]-V[i-1]-2*C+2*table[i][0])
        rclo_1 = max(rclo_1,V[N-1]-V[i-1]-C+table[i][0])
        rclo_2 = max(rclo_2,V[N-1]-V[i-1]-2*C+2*table[i][0])
ans=max(ans,V[N-1]-C+table[0][0])
ans =max(ans,clo_1+rclo_2)
ans =max(ans,clo_2+rclo_1)
#print(clo_1+rclo_2)
#print(clo_2+rclo_1)
print(ans)