N, C = list(map(int, input().split()))
sushi = []
for i in range(N):
    sushi.append(list(map(int, input().split())))

def solve():
    # 時計回り進むだけ
    right_cal = []
    walked = 0
    sum_cal = 0
    for i in range(len(sushi)):
        now_cal = sushi[i][1]
        right_cal.append(now_cal + sum_cal - sushi[i][0])
        sum_cal += now_cal

    # 時計回り折り返し
    right_cal_r = []
    walked = 0
    sum_cal = 0
    for i in range(len(sushi)):
        now_cal = sushi[i][1]
        right_cal_r.append(now_cal + sum_cal - sushi[i][0]*2)
        sum_cal += now_cal


    # 反時計回り
    left_cal = []
    walked = 0
    sum_cal = 0
    for i in range(len(sushi)):
        left_index = len(sushi)-i-1
        now_cal = sushi[left_index][1]
        left_cal.append(now_cal + sum_cal - (C - sushi[left_index][0]))
        sum_cal += now_cal

    # 反時計回り折り返し
    left_cal_r = []
    walked = 0
    sum_cal = 0
    for i in range(len(sushi)):
        left_index = len(sushi)-i-1
        now_cal = sushi[left_index][1]
        left_cal_r.append(now_cal + sum_cal - (C - sushi[left_index][0])*2)
        sum_cal += now_cal

    #反時計周り→時計回りの場合
    left_right_cal = [max(left_cal)]
    for i in range(N):
        if N - i - 1 > 0:
            left_right_cal.append(right_cal_r[i] + max(left_cal[:N - i - 1]))
    #時計周り→反時計回りの場合
    right_left_cal = [max(right_cal)]
    for i in range(N):
        if N - i - 1 > 0:
            right_left_cal.append(left_cal_r[i] + max(right_cal[:N - i - 1]))

    print(max(max(left_right_cal), max(right_left_cal), 0))

if __name__ == '__main__':
    solve()