N,C = list(map(int,input().split()))
nums = [ list(map(int,input().split()))  for i in range(N) ]

plus_arr=[]
plus_max=0
plus_max_num=-1
plus_max_minus_distance=0
plus_max_minus_distance_num=-1
plus_max_half=0
minus_arr=[]
minus_max=0
minus_max_num=N
minus_max_half=0
minus_max_minus_distance=0
minus_max_minus_distance_num=N
for i,(x,v) in enumerate(nums):
    if i == 0:
        vi = v- x
        plus_arr.append(v-x)
        #plus_max=v-x
        #plus_max_num=x
        #plus_max_minus_distance=v-x
        #plus_max_minus_distance_num=x
    else:
        vi = plus_arr[i-1] + nums[i-1][0] -x + v
        plus_arr.append( vi  )
    if plus_max <= vi:
        plus_max = vi
        plus_max_num  = x
    if 2 * x < C:
        plus_max_half = plus_max
        if plus_max_minus_distance <= vi - x:
            plus_max_minus_distance = vi - x
            plus_max_minus_distance_num = x

for i,(x,v) in enumerate(nums[::-1]):
    if i == 0:
        vi = v- C + x
        minus_arr.append(v- C + x)
        #minus_max=v- C + x
        #minus_max_num=x
        #minus_max_minus_distance=v- C + x
        #minus_max_minus_distance_num=x
    else:
        vi = minus_arr[i-1] - nums[N-i][0]  + x + v
        minus_arr.append( vi  )
    if minus_max <= vi:
        minus_max = vi
        minus_max_num  = x
    if 2 * (C - x) < C:
        minus_max_half=minus_max
        if minus_max_minus_distance <= vi -  C + x:
            minus_max_minus_distance = vi -  C + x
            minus_max_minus_distance_num = x
print(max([ plus_max,minus_max,minus_max,plus_max_minus_distance + minus_max_half, plus_max_half+ minus_max_minus_distance]))
