#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, c;
int x[100010], v[100010];

main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> c;
    for(int i = 0; i < n; i++) cin >> x[i] >> v[i];
    int cur = 0;
    int an = 0;
    int pos = 0;
    for(int i = 0; i < n; i++){
        cur -= (x[i] - pos);
        cur += v[i];
        an = max(an, cur);
        pos = x[i];
    }
    pos = 0;
    cur = 0;
    for(int i = n - 1; i >= 0; i--){
        int X = c - x[i];
        cur -= (X - pos);
        cur += v[i];
        an = max(an, cur);
        pos = X;
    }
    vector<pair<int, int>> left, right;
    for(int i = 0; i < n; i++){
        if(x[i] * 2 < c) left.push_back({x[i], v[i]});
    }
    for(int i = n - 1; i >= 0; i--){
        int X = c - x[i];
        if(X * 2 <= c) right.push_back({X, v[i]});
    }
    int left1 = 0, left2 = 0;
    int right1 = 0, right2 = 0;
    pos = 0;
    cur = 0;
    for(auto u: left){
        cur -= (u.first - pos);
        cur += u.second;
        left1 = max(left1, cur);
        pos = u.first;
    }
    pos = 0;
    cur = 0;
    for(auto u: left){
        cur -= 2 * (u.first - pos);
        cur += u.second;
        left2 = max(left2, cur);
        pos = u.first;
    }
    pos = 0;
    cur = 0;
    for(auto u: right){
        cur -= (u.first - pos);
        cur += u.second;
        right1 = max(right1, cur);
        pos = u.first;
    }
    pos = 0;
    cur = 0;
    for(auto u: right){
        cur -= 2 * (u.first - pos);
        cur += u.second;
        right2 = max(right2, cur);
        pos = u.first;
    }
    an = max(an, left1 + right2);
    an = max(an, left2 + right1);
    cout << an << endl;
}
