### BUGGY CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, C: int, x: "List[int]", v: "List[int]"):

    ans = -INF
    hantokeix = [C-el for el in x][::-1]
    hantokeiv = v[::-1]
    for i in range(N):
        # 反時計にi個とってから時計回り
        tot = [0]
        j = 0
        curr = 0
        for j in range(i):
            tot.append(tot[-1] + hantokeiv[j]-(hantokeix[j]-curr))
            curr = hantokeix[j]
        # ターン
        curr = -curr
        for j in range(N-i):
            tot.append(tot[-1]+v[j]-(x[j]-curr))
            curr = x[j]
        sairyo = max(tot)
        ans = max(ans, sairyo)

    for i in range(N):
        # 時計周りにi個とってから反時計回り
        tot = [0]
        j = 0
        curr = 0
        for j in range(i):
            tot.append(tot[-1] + v[j]-(x[j]-curr))
            curr = x[j]
        # ターン
        curr = -curr
        for j in range(N-i):
            tot.append(tot[-1]+hantokeiv[j]-(hantokeix[j]-curr))
            curr = hantokeix[j]
        sairyo = max(tot)
        ans = max(ans, sairyo)

    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, C, x, v)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from itertools import accumulate
INF = float("inf")


def solve(N: int, C: int, x: "List[int]", v: "List[int]"):

    # 時計回りターンなし
    nt_cost = x
    nt_benefit = list(accumulate(v))
    nt_callory = [b-c for c, b in zip(nt_cost, nt_benefit)]
    nt_callory_acc = list(accumulate(nt_callory, max)) + [0]
    # [0]はモンキーパッチ。後に負の参照をした場合に参照させる用
    # print(nt_callory)
    # print(nt_callory_acc)

    # 反時計回りターンなし
    rnt_cost = list((reversed([C-v for v in x])))
    rnt_benefit = list(accumulate(reversed(v)))
    rnt_callory = [b-c for c, b in zip(rnt_cost, rnt_benefit)]
    rnt_callory_acc = list(accumulate(rnt_callory, max)) + [0]
    # print(rnt_callory)
    # print(rnt_callory_acc)

    # 時計回り
    m = -INF
    for i in range(N):
        # i番目でターン
        callory = max(nt_callory[i]-nt_cost[i]+rnt_callory_acc[N-i-2],
                      nt_callory[i])
        # print(i, callory)
        m = max(m, callory)

    # 反時計回り
    for i in range(N):
        # i番目でターン
        callory = max(rnt_callory[i]-rnt_cost[i]+nt_callory_acc[N-i-2],
                      rnt_callory[i])
        # print(i, callory)
        m = max(m, callory)

    print(max(0, m))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, C, x, v)


if __name__ == '__main__':
    main()