N, C = [int(_) for _ in input().split()]
xv = [[int(_) for _ in input().split()] for i in range(N)]

def solve(N, C, xv):
    
    from itertools import accumulate

    xs = [0] + [_[0] for _ in xv] + [C]
    vs = [0] + [_[1] for _ in xv] + [0]
    xs_rev = [C - x for x in xs[::-1]]
    vs_rev = vs[::-1]

    ts = accumulate(vs)
    txs = [t - x for x, t in zip(xs, ts)]
    maxtxs = list(accumulate(txs, max))

    ts_rev = accumulate(vs_rev)
    txs_rev = [t - x for x, t in zip(xs_rev, ts_rev)]
    maxtxs_rev = list(accumulate(txs_rev, max))

    result = 0
    for i, tx in enumerate(txs_rev[:-1]):
        r = tx - xs_rev[i] + maxtxs[N - i]
        result = max(result, r)
    for i, tx in enumerate(txs[:-1]):
        r = tx - xs[i] + maxtxs_rev[N - i]
        result = max(result, r)

    return result

print(solve(N, C, xv))
