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
for i in range(N):
    #print(V[i]-table[i][0])
    ans=max(ans,V[i]-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])
ans=max(ans,V[N-1]-C+table[0][0])
#print(V[N-1]-C+table[0][0])
#print(1)
for i in range(N):
    for k in range(i+1,N):
        #print(V[i]+V[N-1]-V[k-1]-C-2*table[i][0]+table[k][0])
        #print(V[i]+V[N-1]-V[k-1]-table[i][0]-2*C+2*table[k][0])
        ans = max(ans, V[i]+V[N-1]-V[k-1]-C-2*table[i][0]+table[k][0])
        ans = max(ans,V[i]+V[N-1]-V[k-1]-table[i][0]-2*C+2*table[k][0])
print(ans)