def solve():
    N, C = map(int, input().split())# {{{
    L = [0]*N
    R = [0]*N

    S = []
    for n in range(N):
        x, v = map(int, input().split())
        S.append((x,v))
    res = 0

    # left round
    pre_x = 0
    diff = 0
    M = 0
    for n in range(N):
        x, v = S[n]
        diff -= abs(x - pre_x)
        diff += v
        M = max(diff, M)
        res = max(res, M)
        L[n] = M
        pre_x = x

    # print(L)

    # right round
    pre_x = C
    diff = 0
    M = 0
    for n in range(1, N+1):
        x, v = S[-n]
        diff -= abs(x - pre_x)
        diff += v
        M = max(diff, M)
        res = max(res, M)
        R[-n] = M
        pre_x = x

    # print(R)
    # }}}

    # left, right
    diff = 0
    for n in range(N-1):
        res = max(res, L[n]-S[n][0] + R[n+1])

    # right, left
    diff = 0
    for n in range(1, N):
        res = max(res, R[-n]-(abs(C-S[-n][0])) + L[-n-1])

    print(res)

if __name__ == "__main__":
    solve()
