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

V.insert(0, 0)
V.append(0)
X.insert(0, 0)
X.append(C)

clockwise = [sum(V[:i+1]) - X[i] for i in range(N+1)]
counterclockwise = [sum(V[i:]) - C + X[i] for i in range(1,N+2)]

clockwisemax = [max(clockwise[:i+1]) for i in range(N+1)]
counterclockwisemax = [max(counterclockwise[i:]) for i in range(N+1)]



value_list = []
for i in range(N+1):
    value_list.append(clockwisemax[i])
    value_list.append(clockwisemax[i] - X[i] + counterclockwisemax[i])
    value_list.append(counterclockwisemax[i])
    value_list.append(counterclockwisemax[i] - C + X[i+1] + clockwisemax[i])


print(max(value_list))