def solve(sushi, n, c):
    max_val = -1
    for last_cw in xrange(n):
        for last_ccw in xrange(last_cw + 1, n):
            cw_value = sublist_cw[last_cw]
            ccw_value = sublist_ccw[last_ccw]
            walking = min(sushi[last_cw][0] * 2 + (c - sushi[last_ccw][0]),
                          (c - sushi[last_ccw][0]) * 2 + sushi[last_cw][0])
            val = cw_value + ccw_value - walking
            if val > max_val:
                max_val = val

    # no cw
    for last_ccw in xrange(n):
        ccw_value = sublist_ccw[last_ccw]
        walking = c - sushi[last_ccw][0]
        val = ccw_value - walking
        if val > max_val:
            max_val = val

    #no ccw
    for last_cw in xrange(n):
        cw_value = sublist_cw[last_cw]
        walking = sushi[last_cw][0]
        val = cw_value - walking
        if val > max_val:
            max_val = val

    return max(max_val, 0)


n,c  = map(int, raw_input().split())
sushi = []
for _ in xrange(n):
    sushi.append(tuple(map(int, raw_input().split())))

sublist_cw = [sushi[0][1]]
for i in xrange(1, len(sushi)):
    sublist_cw.append(sublist_cw[-1] + sushi[i][1])

sublist_ccw = [sushi[-1][1]]
for i in xrange(len(sushi) - 2, -1, -1):
    sublist_ccw.insert(0, sublist_ccw[0] + sushi[i][1])

print solve(sushi, n, c)
