#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N;
    LL C; cin >> C;
    vector<LL> x(N), v(N);
    REP(i,N)
    {
        cin >> x[i] >> v[i];
    }

    vector<LL> f(N);
    vector<LL> rf(N);
    LL acc = 0;
    LL racc = 0;
    REP(i,N) // calculate f :: ok
    {
        acc += v[i];
        if(i == 0)
        {
            acc -= x[0];
        }
        else
        {
            acc -= x[i] - x[i-1];
        }
        f[i] = acc;
        dump(f[i])
    }

    REP(i,N) // calculate rf :: ok
    {
        racc += v[N-1-i];
        if(i == 0)
        {
            racc -= C - x[N-1-i];
        }
        else
        {
            racc -= abs(x[N-1-i] - x[N-i]);
        }
        rf[i] = racc;
        dump(rf[i])
    }

    vector<int> memo(N); // memo[a]はa以下の選択肢の中で，最も効率の良い寿司ネタを表す
    vector<int> rmemo(N);
    REP(i,N) //memo
    {
        if(i == 0)
        {
            memo[0] = 0;
        }
        else
        {
            if(f[i] > f[memo[i-1]]) memo[i] = i;
            else memo[i] = memo[i-1];
        }
    }
    REP(i,N) //rmemo
    {
        if(i == 0)
        {
            rmemo[0] = 0;
        }
        else
        {
            if(rf[i] > rf[rmemo[i-1]]) rmemo[i] = i;
            else rmemo[i] = rmemo[i-1];
        }
    }

    LL kouho = -1 * LINF;

    dump("time1")
    REP(i,N) //最初は順周り
    {
        LL tmp;
        if(i != N-1)
        {
            tmp = f[i] + rf[rmemo[N-2-i]] - x[i];
        }
        else
        {
            tmp = f[i];
        }
        dump(i)
        dump(tmp)

        if(tmp > kouho) kouho = tmp;

    }
    dump("time2")
    REP(i,N) //最初は逆順周り
    {
        LL tmp;
        if(i != N-1)
        {
            tmp = rf[i] + f[memo[N-2-i]] - (C - x[N-1-i]);
        }
        else
        {
            tmp = rf[i];
        }
        if(tmp > kouho) kouho = tmp;
    }

    dump("time3")
    REP(i,N) //最初は順周りで，戻らない
    {
        LL tmp = f[i];
        dump(tmp)
        if(tmp > kouho) kouho = tmp;
    }
    dump("time4")
    REP(i,N)
    {
        LL tmp = rf[i];
        dump(tmp)
        if(tmp > kouho) kouho = tmp;
    }

    cout << max(kouho,0LL) << endl;

}


Measured memory_bytes: 4224