#ifndef __SEGMENT_TREE__H__
#define __SEGMENT_TREE__H__

#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>

/*
* std::min を使う際、
*		SegmentTree<int> seg(N, INF, (const int&(*)(const int&, const int&))std::min);
* と書かなければならないので、後述の Min を使って
*		SegmentTree<int> seg(N, INF, Min<int>());
* とする。
*/
template <typename T>
class SegmentTree {
	using FuncType = std::function<T(const T&, const T&)>;

private:
	T* val_p_m;
	const T init_val_m;
	const int size_m;
	const int rank_m;

	const FuncType func_m;

	T Query_rec(int range_left, int range_right, int node_index, int node_range_left, int node_range_right);
	bool Is_valid_index(int index);
public:
	SegmentTree(int size, const T& init_val, const FuncType& func);
	~SegmentTree();

	void Update(int pos, const T& val);
	T Query(int range_left, int range_right);
};

template<typename T>
T SegmentTree<T>::Query_rec(int range_left, int range_right, int node_index, int node_range_left, int node_range_right) {
	if (node_range_right <= range_left || range_right <= node_range_left) return init_val_m;
	if (range_left <= node_range_left && node_range_right <= range_right) return val_p_m[node_index];

	int node_range_mid = (node_range_left + node_range_right) / 2;
	const T val_left = Query_rec(range_left, range_right, node_index * 2, node_range_left, node_range_mid);
	const T val_right = Query_rec(range_left, range_right, node_index * 2 + 1, node_range_mid, node_range_right);
	return func_m(val_left, val_right);
}

template<typename T>
inline bool SegmentTree<T>::Is_valid_index(int index) {
	return index >= 0 && index < size_m;
}

template<typename T>
SegmentTree<T>::SegmentTree(int size, const T& init_val, const FuncType& func)
	: init_val_m(init_val), size_m(size), rank_m((int)std::log2(size - 1) + 2), func_m(func) {

	val_p_m = new T[1 << rank_m];
	std::fill(val_p_m + (1 << (rank_m - 1)), val_p_m + (1 << rank_m), init_val_m);

	for (int i = (1 << (rank_m - 1)) - 1; i >= 1; --i) {
		val_p_m[i] = func_m(val_p_m[i * 2], val_p_m[i * 2 + 1]);
	}
}

template<typename T>
inline SegmentTree<T>::~SegmentTree() {
	delete[] val_p_m;
}

template<typename T>
void SegmentTree<T>::Update(int pos, const T& val) {
	assert(Is_valid_index(pos));

	int i = pos + (1 << (rank_m - 1));
	val_p_m[i] = val;
	while (i > 1) {
		i /= 2;
		val_p_m[i] = func_m(val_p_m[i * 2], val_p_m[i * 2 + 1]);
	}
}

template<typename T>
T SegmentTree<T>::Query(int range_left, int range_right) {
	assert(Is_valid_index(range_left));
	assert(Is_valid_index(range_right - 1));

	return Query_rec(range_left, range_right, 1, 0, 1 << (rank_m - 1));
}

template<typename T>
struct Max {
	const T& operator()(const T& a, const T& b) const { return std::max<T>(a, b); }
};
template<typename T>
struct Min{
	const T& operator()(const T& a, const T& b) const { return std::min<T>(a, b); }
};

#endif

#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i)
#define ALL(arr) (arr).begin(), (arr).end()
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
template <class T>
T Next() { T buf; cin >> buf; return buf; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#include "Segment_Tree.h"
#include "Rational.h"
#include "Position.h"
#include "Factorization.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
template <class T>
auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; }
#endif

LL N, C;
LL X[100000], V[100000];

LL Sub() {
	SegmentTree<LL> seg(N, -INFLL, Max<LL>());

	LL ss = 0;
	REP(i, 0, N) {
		ss += V[i];
		seg.Update(i, ss - X[i]);
	}

	LL ret = 0;
	ret = max(ret, seg.Query(0, N));

	LL tmp = 0;
	LL prev = C;
	REM(i, 1, N) {
		tmp += V[i];
		LL ans = tmp - (C - X[i]) * 2 + seg.Query(0, i);
		ret = max(ret, ans);
	}
	return ret;
}

int main() {
	cin >> N >> C;
	REP(i, 0, N) {
		cin >> X[i] >> V[i];
	}
	LL ans = Sub();
	reverse(X, X + N);
	reverse(V, V + N);
	REP(i, 0, N) {
		X[i] = C - X[i];
	}

	ans = max(ans, Sub());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3840