n,c = map(int,input().split())
sushi_li = [list(map(int,input().split())) for i in range(n)]

ans = 0
goleftsushi = 0
goleftwalk = 0

rightmax = [0 for i in range(n)]
rightmaxtmp = 0

gorightsushi = 0
gorightwalk = 0

rightmaxpos=0

for j in range(n-1,0,-1):
    gorightsushi = gorightsushi + sushi_li[j][1]
    gorightwalk = c - sushi_li[j][0]
    if rightmaxtmp <= gorightsushi-gorightwalk:
        rightmaxtmp = gorightsushi - gorightwalk
        rightmaxpos=j
    rightmax[j] = rightmaxtmp

ans = max(rightmaxtmp,0)

for i in range(n):
    goleftsushi = goleftsushi + sushi_li[i][1]
    goleftwalk = sushi_li[i][0]
    if i < n-1:
        tmpans = goleftsushi-goleftwalk + max(0,rightmax[i+1]-sushi_li[i][0])
    else:
        tmpans = goleftsushi - goleftwalk
    if ans <= tmpans:
        ans = tmpans


print(ans)
