N, C = map(int, input().split())
sushi_m_kcal = []
for i in range(N):
    sushi_m_kcal.append(list(map(int, input().split())))
sorted_sushi = sorted(sushi_m_kcal)
reversed_sushi = sorted(sushi_m_kcal, reverse=True)
sorted_result = []
reversed_result = []
for i in range(N):
    sorted_kcal = 0
    reversed_kcal = 0
    for j in range(-i, N - i):
        sorted_kcal += sorted_sushi[j][1]
        reversed_kcal += reversed_sushi[j][1]
        if i != 0:
            sorted_result.append(sorted_kcal - sorted_sushi[j][0] + 2 * (sorted_sushi[-i][0] - C))
            reversed_result.append(reversed_kcal - C + reversed_sushi[j][0] - 2 * reversed_sushi[-i][0])
        else:
            sorted_result.append(sorted_kcal - sorted_sushi[j][0])
            reversed_result.append(reversed_kcal - C + reversed_sushi[j][0])

print(max(0, max(sorted_result), max(reversed_result)))