#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N-1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N-1, 0)
const ll INF = 1LL << 60;
const int INF_INT = 1 << 30;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
struct mll {
	static ll MOD;
	ll val;
	mll(ll v = 0) : val(v % MOD) { if (val < 0) val += MOD; }
	mll operator - () const { return -val; }
	mll operator + (const mll &b) const { return val + b.val; }
	mll operator - (const mll &b) const { return val - b.val; }
	mll operator * (const mll &b) const { return val * b.val; }
	mll operator / (const mll &b) const { return mll(*this) /= b; }
	mll operator + (ll b) const { return *this + mll(b); }
	mll operator - (ll b) const { return *this - mll(b); }
	mll operator * (ll b) const { return *this * mll(b); }
	friend mll operator + (ll a, const mll &b) { return b + a; }
	friend mll operator - (ll a, const mll &b) { return -b + a; }
	friend mll operator * (ll a, const mll &b) { return b * a; }
	mll &operator += (const mll &b) { val = (val + b.val) % MOD; return *this; }
	mll &operator -= (const mll &b) { val = (val + MOD - b.val) % MOD; return *this; }
	mll &operator *= (const mll &b) { val = (val*b.val) % MOD; return *this; }
	mll &operator /= (const mll &b) {
		ll c = b.val, d = MOD, u = 1, v = 0;
		while (d) {
			ll t = c / d;
			c -= t * d; swap(c, d);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	mll &operator += (ll b) { return *this += mll(b); }
	mll &operator -= (ll b) { return *this -= mll(b); }
	mll &operator *= (ll b) { return *this *= mll(b); }
	mll &operator /= (ll b) { return *this /= mll(b); }
	bool operator == (const mll &b) { return val == b.val; }
	bool operator != (const mll &b) { return val != b.val; }
	bool operator == (ll b) { return *this == mll(b); }
	bool operator != (ll b) { return *this != mll(b); }
	friend bool operator == (ll a, const mll &b) { return mll(a) == b.val; }
	friend bool operator != (ll a, const mll &b) { return mll(a) != b.val; }
	friend ostream &operator << (ostream &os, const mll &a) { return os << a.val; }
	friend istream &operator >> (istream &is, mll &a) { return is >> a.val; }
	static mll Combination(ll a, ll b) {
		chmin(b, a - b);
		if (b < 0) return mll(0);
		mll c = 1;
		rep(i, b) c *= a - i;
		rep(i, b) c /= i + 1;
		return c;
	}
};
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;

struct Fast {
	Fast() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast; //cin,cout高速化のおまじない＋桁数指定

ll mll::MOD = (ll)(1e9 + 7);// 998244353ll;


template<typename Monoid>
struct SegmentTree {
	using F = function< Monoid(Monoid, Monoid) >;

	ll sz;
	vector<Monoid> seg;

	const F f;
	const Monoid M1;

	SegmentTree(ll n, const F f, const Monoid &M1) : f(f), M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(ll k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (ll k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(ll k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(ll a, ll b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid operator[](const ll &k) const {
		return seg[k + sz];
	}

	template< typename C >
	ll find_subtree(ll a, const C &check, Monoid &M, bool type) {
		while (a < sz) {
			Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
			if (check(nxt)) a = 2 * a + type;
			else M = nxt, a = 2 * a + 1 - type;
		}
		return a - sz;
	}

	template<typename C>
	ll find_first(ll a, const C &check) {
		Monoid L = M1;
		if (a <= 0) {
			if (check(f(L, seg[1]))) return find_subtree(1, check, L, false);
			return -1;
		}
		ll b = sz;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) {
				Monoid nxt = f(L, seg[a]);
				if (check(nxt)) return find_subtree(a, check, L, false);
				L = nxt;
				++a;
			}
		}
		return -1;
	}

	template<typename C>
	ll find_last(ll b, const C &check) {
		Monoid R = M1;
		if (b >= sz) {
			if (check(f(seg[1], R))) return find_subtree(1, check, R, true);
			return -1;
		}
		ll a = sz;
		for (b += sz; a < b; a >>= 1, b >>= 1) {
			if (b & 1) {
				Monoid nxt = f(seg[--b], R);
				if (check(nxt)) return find_subtree(b, check, R, true);
				R = nxt;
			}
		}
		return -1;
	}
};

//SegmentTree(n, f, M1):= サイズ n の初期化。ここで f は2つの区間の要素をマージする二項演算, M1 はモノイドの単位元である。
//set(k, x):= k 番目の要素に x を代入する。
//build():= セグメント木を構築する。
//query(a, b):= 区間 [a,b) に対して二項演算した結果を返す。
//update(k, x):= k 番目の要素を x に変更する。
//operator[k] := k 番目の要素を返す。
//find_first(a, check) := [a,x) が check を満たす最初の要素位置 x を返す。
//find_last(b, check) := [x,b) が check を満たす最後の要素位置 x を返す。

//使用例
//int main() {
//	int N, Q;
//	scanf("%d %d", &N, &Q);
//	SegmentTree< int > seg(N, [](int a, int b) { return min(a, b); }, INF_INT);
//	while (Q--) {
//		int T, X, Y;
//		scanf("%d %d %d", &T, &X, &Y);
//		if (T == 0) seg.update(X, Y);
//		else printf("%d\n", seg.query(X, Y + 1));
//	}
//}

struct LLPair {
	ll x = 0;
	ll v = 0;
	LLPair() {}
	LLPair(ll x, ll v) {
		this->x = x;
		this->v = v;
	}
};

int main() {
	ll N;
	cin >> N;
	ll C;
	cin >> C;
	vector<LLPair> A(N);
	rep(i, N) {
		cin >> A[i].x >> A[i].v;
	}

	ll result = 0;

	{
		//順周りである寿司まで考慮したときのカロリー利得最大値を求めるためのセグ木を作成
		SegmentTree<ll> seg(N, [](ll a, ll b) { return max(a, b); }, -INF);
		ll gain = 0;
		rep(i, N) {
			gain += A[i].v;
			gain -= i == 0 ? A[i].x : (A[i].x - A[i - 1].x);
			seg.update(i, gain);
		}

		//逆回りせず順回りだけの場合
		chmax(result, seg.query(0, N));

		//逆回りでひとつずつ検証
		ll get = 0;
		ll cost = 0;
		dep(i, N) {
			get += A[i].v;
			cost += i == N - 1 ? (C - A[i].x) : (A[i + 1].x - A[i].x);
			ll tempGain = get - cost;

			//引き返さない場合
			chmax(result, tempGain);

			//引き返す場合
			chmax(result, tempGain - cost + seg.query(0, i));
		}
	}

	{
		//逆周りである寿司まで考慮したときのカロリー利得最大値を求めるためのセグ木を作成
		SegmentTree<ll> seg(N, [](ll a, ll b) { return max(a, b); }, -INF);
		ll get = 0;
		ll cost = 0;
		dep(i, N) {
			get += A[i].v;
			cost += i == N - 1 ? (C - A[i].x) : (A[i + 1].x - A[i].x);
			seg.update(i, get - cost);
		}

		//順回りせず逆回りだけの場合
		chmax(result, seg.query(0, N));

		//順回りでひとつずつ検証
		get = 0;
		cost = 0;
		rep(i, N) {
			get += A[i].v;
			cost += i == 0 ? A[i].x : (A[i].x - A[i - 1].x);
			ll tempGain = get - cost;

			//引き返さない場合
			chmax(result, tempGain);

			//引き返す場合
			chmax(result, tempGain - cost + seg.query(i + 1, N));
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 3964