/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Gosu_Hiroo
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define TR(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define IN(c, x) ((c).find(x) != (c).end())   //O(log n)
#define IN_L(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define FOR(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define MOD(x, m) ((((x) % (m)) + (m)) % (m))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define READ ({int t;cin >> t;t;})
#define EB emplace_back
#define fcout cout << fixed << setprecision(12)
#define fcerr cerr << fixed << setprecision(12)
#define print(x) cout << (x) << endl

#ifdef DEBUG
#define ERR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); _err(cerr,_it, args); }
#define DBG(x) cerr << #x << " is " << x << endl;
#else
#define DBG(x) {};
#define ERR(args...) {};
#endif
void _err(std::ostream& cerr,istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>
void _err(std::ostream& cerr, istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    _err(cerr,++it, args...);
}

const double pi = 2 * acos(.0);
const int inf = 0x3f3f3f3f;
const ll mod = (ll) (1e9) + 7;
//const ll mod = (ll) 998244353 ;
const double eps = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template <typename T>
ostream& operator << (ostream& os, const vector<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template <typename T>
ostream& operator << (ostream& os, const deque<T> V) {
    for(auto v : V)os << v << " ";
    return os;
}

template<class T>bool Chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool Chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//#define int ll

class DStaticSushi {
public:
    int N;
    ll C,x[101010],v[101010];
    vector<PLL>pro, r_pro;
void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) {
    cin >> N >> C;
    REP(i,N)cin >> x[i] >> v[i];
    ll eat = 0, mx = 0;
    pro.EB(0,0);
    r_pro.EB(0,0);
    REP(i,N){
        eat += v[i];
        if(Chmax(mx, eat - x[i]))pro.EB(x[i], eat - x[i]);
    }
    eat = 0, mx = 0;
    FOR(i,N,0){
        eat += v[i];
        if(Chmax(mx, eat - (C-x[i])))r_pro.EB(C-x[i], eat - (C-x[i]));
    }

    ll ans = -1;
    REP(i,SZ(r_pro)){
        auto it = lower_bound(ALL(pro), (PLL){C-r_pro[i].F,-1}) -1;
        if(it !=pro.end()){
            ERR(r_pro[i].F, r_pro[i].S)
            ERR(i,it->F, it->S)
            Chmax(ans, r_pro[i].S-r_pro[i].F + it->S);
        }
    }
    REP(i,SZ(pro)){
        auto it = lower_bound(ALL(r_pro), (PLL){C-pro[i].F,-1}) -1;
        if(it !=pro.end()){
            ERR(r_pro[i].F, r_pro[i].S)
            ERR(i,it->F, it->S)
            Chmax(ans, pro[i].S-pro[i].F + it->S);
        }
    }

//    REP(i,SZ(pro))if( lower_bound(ALL(r_pro), (PLL){C-r_pro[i].F,-1}) != r_pro.end())Chmax(ans, pro[i].S-pro[i].F + lower_bound(ALL(r_pro), (PLL){C-r_pro[i].F,-1})->second);
    print(ans);

}


};


#undef int
int main() {

	DStaticSushi solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
    std::ostringstream err;
	in.tie(0); ios::sync_with_stdio(0);
//	solver.solve(in, out);
    solver.solve(in, out,err);
	return 0;
}


Measured memory_bytes: 6512