def new_location(old_location, new_zero, c):
    if old_location < new_zero:
        return c + (old_location - new_zero)
    else:
        return old_location - new_zero


def solve(sushi, c):
    if sushi:
        new_list = map(lambda (x,y):(new_location(x, sushi[0][0], c), y), sushi[1:])
        cw_sushi = solve(new_list, c) + sushi[0][1] - min(sushi[0][0], c - sushi[0][0])
        if len(sushi) > 1:
            new_list = map(lambda (x,y):(new_location(x, sushi[-1][0], c), y), sushi[:-1])
            ccw_sushi = solve(new_list, c) + sushi[-1][1] - min(sushi[-1][0], c - sushi[-1][0])
            return max(0, cw_sushi, ccw_sushi)

        return max(0, cw_sushi)

    return 0


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

print solve(sushi, c)