n, c = map(int, input().split())

s = [tuple(map(int, input().split()))for _ in range(n)]

normal = [s[0][1] - s[0][0]] # 
cur = normal[0]
n_max = max(0, normal[0])

for (s1_pos, s1_cal), (s2_pos, s2_cal) in zip(s, s[1:]):
    cur = cur + s2_cal - (s2_pos - s1_pos)
    if n_max < cur:
        n_max = cur
    normal.append(n_max)

reverse = [s[-1][1] - (c - s[-1][0])]
cur = reverse[0]
r_max = max(0, reverse[0])
         
for (s1_pos, s1_cal), (s2_pos, s2_cal) in zip(s[::-1], s[-2::-1]):
    cur = cur + s2_cal - (s1_pos-s2_pos)
    if r_max < cur:
        r_max = cur
    reverse.append(r_max)
         
res = 0
for i, (pos, cal) in enumerate(s[:-1]):
    res = max(res, normal[i], normal[i]-pos+reverse[n-2-i])
for i, (pos, cal) in enumerate(s[:0:-1]):
    res = max(res, reverse[i], reverse[i]-(c-pos)+normal[n-2-i])
res = max(res, normal[-1], reverse[-1])
         
print(res)