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

#define int long long
typedef pair<int, int> P;
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#endif

#define mod 1000000007





void solve(){
    int N, C;
    cin >> N >> C;
    vector<int> x(N), v(N);
    rep(i,N) cin >> x[i] >> v[i];
    
    vector<int> right1(N,0), right2(N,0);
    int sum = 0;
    rep(i,N){
        sum += v[i];
        if(i==0){
            right1[i] = sum - x[0];
            right2[i] = sum - x[0] * 2;
        }else{
            right1[i] = max(right1[i-1], sum - x[i]);
            right2[i] = max(right2[i-1], sum - x[i] * 2);
        }
    }
    
    vector<int> left1(N,0), left2(N,0);
    sum = 0;
    for(int i=N-1; i>=0; i--){
        sum += v[i];
        if(i==N-1){
            left1[i] = sum - (C-x[i]);
            left2[i] = sum - (C-x[i])*2;
        }else{
            left1[i] = max(left1[i+1], sum - (C-x[i]));
            left2[i] = max(left2[i+1], sum - (C-x[i])*2);
        }
    }
    
    dump(right1, right2, left1, left2);
    
    int ans = 0;
    ans = max(ans, right1[N-1]);
    ans = max(ans, left1[0]);
    
    rep(i,N-1){
        ans = max(ans, right2[i] + left1[i+1]);
    }
    for(int i=N-1; i>=1; i--){
        ans = max(ans, left2[i] + right1[i-1]);
    }
    
    cout << ans << endl;
}

signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 4992