import random


def slv(N, C, X, V):
    # cal_l = 0
    # move = 0
    # for x, v in zip(X, V):
    #     if x-move > v:
    #         break
    #     cal_l += v
    #     move = x
    # cal_l -= move

    # cal_r = 0
    # move = 0
    # tmp =list(zip(X, V))
    # for x, v in tmp[::-1]:
    #     if (C-x)-move > v:
    #         break
    #     cal_r += v
    #     move = C - x
    # cal_r -= move

    # print(cal_l, cal_r)

    ans_l = [(0, 0)]
    for x, v in zip(X, V):
        ans_l.append((x, ans_l[-1][1] + v))

    ans_r = [(0, 0)]
    for x, v in list(zip(X, V))[::-1]:
        ans_r.append((C-x, ans_r[-1][1] + v))


    ans_l_r = []
    for i, a in enumerate(ans_l):
        tmp = 0
        for b in ans_r[:-i]:
            c = a[1] + b[1] - 2*a[0] - b[0]
            tmp = max(tmp, c)
        ans_l_r.append( tmp)
    ans_r_l = []
    for i, a in enumerate(ans_r):
        tmp = 0
        for b in ans_l[:-i]:
            c = a[1] + b[1] - 2*a[0] - b[0]
            tmp = max(tmp, c)
        ans_r_l.append( tmp)

    
    # print(ans_l)
    # print(ans_r)
    l = max([x[1]-x[0] for x in ans_l])
    r = max([x[1]-x[0] for x in ans_r])
    lr = max(ans_l_r)
    rl = max(ans_r_l)


    return max(l, r, lr, rl)



def main():
    N, C = list(map(int, input().split()))
    X = []
    V = []
    for _ in range(N):
        x, v = list(map(int, input().split()))
        X.append(x)
        V.append(v)
    print(slv(N, C, X, V))


if __name__ == '__main__':
    main()