#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, c = f.read_int_list()
    x = [f.read_int_list() for _ in xrange(n)]

    sl = [0] * n
    mal = [None] * n
    sr = [0] * n
    mar = [None] * n

    pos = 0
    for i in xrange(n):
        if i > 0: sl[i] = sl[i-1]
        sl[i] += x[i][1] - (x[i][0] - pos)
        pos = x[i][0]
        if i > 0:
            if sl[i] > mal[i-1][0]:
                mal[i] = (sl[i], i)
            else:
                mal[i] = mal[i-1]
        else:
            mal[i] = (sl[i], i)

    pos = c
    for i in xrange(n-1,-1,-1):
        if i < n-1: sr[i] = sr[i+1]
        sr[i] += x[i][1] - (pos - x[i][0])
        pos = x[i][0]
        if i < n-1:
            if sr[i] > mar[i+1][0]:
                mar[i] = (sr[i], i)
            else:
                mar[i] = mar[i+1]
        else:
            mar[i] = (sr[i], i)

    # print sl, mal, sr, mar

    ans = 0
    for i in xrange(n):
        ans = max(ans, sl[i])
        if n > 1 and i < n-1: ans = max(ans, sl[i] - x[i][0] + mar[i+1][0])
    for i in xrange(n-1,-1,-1):
        ans = max(ans, sr[i])
        if n > 1 and i > 0: ans = max(ans, sr[i] - (c-x[i][0]) + mal[i-1][0])

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)
