N, C = map(int, input().split())
X, V = [], []
for i in range(N):
    xi, vi = map(int, input().split())
    X.append(xi)
    V.append(vi)

# 時計回り・反時計回りにi個目までの寿司を食べたときに歩く距離
r_cost = [0]
l_cost = [0]
# 時計回り・反時計回りにi個目までの寿司を食べた時の総栄養価
r_value = [0]
l_value = [0]

for i in range(N):
    r_cost.append(X[i])
    l_cost.append(C-X[-i-1])
    r_value.append(r_value[-1] + V[i])
    l_value.append(l_value[-1] + V[-i-1])

# 歩く距離と栄養価を考慮した場合の、引き返してどこまで行くのが最適か
r_optimized = [0]
l_optimized = [0]
for i in range(1, N+1):
    r_optimized.append(r_value[i] - r_cost[i])
    l_optimized.append(l_value[i] - l_cost[i])

# max累積和
for i in range(1, N+1):
    r_optimized[i] = max(r_optimized[i], r_optimized[i-1])
    l_optimized[i] = max(l_optimized[i], l_optimized[i-1])

# 答えを計算
ans = 0
for i in range(N+1):
    r_straight = r_optimized[i]
    l_straight = l_optimized[i]
    r_turn = r_value[i] - 2 * r_cost[i] + l_optimized[N-i]
    l_turn = l_value[i] - 2 * l_cost[i] + r_optimized[N-i]
    ans = max(ans, r_straight, l_straight, r_turn, l_turn)

print(ans)
