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]) for i in range(N+1)]
counterclockwise = [sum(V[i:]) for i in range(1,N+2)]


value_list = []
for i in range(N+1):
    for j in range(i, N+1):
        value = clockwise[i] + clockwise[N] - clockwise[j] - 2 * min(X[i], C - X[j+1]) - max(X[i], C - X[j+1])
        value_list.append(value)


print(max(value_list))