import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, C] = [long(input_raw[0]), long(input_raw[1])]
    x_list = []
    v_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [x, v] = [long(input_raw[0]), long(input_raw[1])]
        x_list.append(x)
        v_list.append(v)

    left_v_sum = [v_list[0]]
    for i in range(1, N):
        left_v_sum.append(left_v_sum[i - 1] + v_list[i])

    right_v_sum = [v_list[N - 1]]
    for i in range(N - 2, -1, -1):
        right_v_sum.append(right_v_sum[N - i - 2] + v_list[i])

    left_max = 0
    for l in range(N):
        left_max = max(left_max, left_v_sum[l] - x_list[l])
        for r in range(N - l - 1):
            left_max = max(left_max, left_v_sum[l] + right_v_sum[r] - (2 * x_list[l] + (C - x_list[N - r - 1])))

    right_max = 0
    for r in range(N):
        right_max = max(right_max, right_v_sum[r] - (C - x_list[N - r - 1]))
        for l in range(N - r - 1):
            right_max = max(right_max, left_v_sum[l] + right_v_sum[r] - (2 *(C - x_list[N - r - 1]) + x_list[l]))

    print max(left_max, right_max)

if __name__ == '__main__':
    main()