#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define LL long long
const int MaxN = 1e5 + 7;
LL a[MaxN], b[MaxN];
LL x[MaxN], v[MaxN];

int main()
{
    LL n, c;
    scanf("%lld%lld", &n, &c);
    for(int i = 1; i <= n; i++)
        scanf("%lld%lld", &x[i], &v[i]);
    for(LL i = 1; i <= n; i++)
        a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]); 
    x[n + 1] = c;
    for(LL i = n; i >= 1; i--)
        b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]); 
    for(LL i = 2; i <= n; i++)
        a[i] = max(a[i-1], a[i]);
    for(LL i = n-1; i >= 1; i--)
        b[i] = max(b[i], b[i + 1]);
    LL ans = max(0LL,max(a[n],b[1]));
    for(LL i = 1; i <= n-2; i++) 
        ans = max(ans, a[i] - x[i] + b[i + 1]);
    for(LL i = 2; i <= n; i++)     
        ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);
    printf("%lld\n", ans);
}
