// Slower C++ solution:
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;



const int N = 100005;

ll n, C, x[N], v[N], pre[N], ans, p, q, ans1, ans2;

ll a[N], b[N], L[N], R[N];



int main() {

    scanf("%lld%lld", &n, &C);

    // 1

    for (int i = 1; i <= n; i++) {

        scanf("%lld%lld", &x[i], &v[i]);

        pre[i] = pre[i - 1] + v[i];

    }

    for (int i = 1; i <= n; i++) {

        ll tmp = pre[i] - x[i];

        a[i] = tmp;

        ans1 = max(ans1, tmp);

    }

    ans = max(ans, ans1);



    // 2

    for (int i = 1; i <= n; i++) pre[i] = v[i];

    for (int i = n; i >= 1; i--) pre[i] += pre[i + 1];

    for (int i = n; i >= 1; i--) {

        ll tmp = pre[i] - (C - x[i]);

        b[i] = tmp;

        ans2 = max(ans2, tmp);

    }

    ans = max(ans, ans2);



    // 3

    for (int i = 1; i <= n; i++) {

        L[i] = max(L[i - 1], a[i] - x[i]);

    }

    for (int i = n; i >= 1; i--) {

        R[i] = max(R[i + 1], b[i]);

    }

    for (int i = 1; i <= n; i++)

        ans = max(ans, L[i] + R[i + 1]);



    // 4

    memset(L, 0, sizeof(L));

    memset(R, 0, sizeof(R));

    for (int i = 1; i <= n; i++) {

        L[i] = max(L[i - 1], a[i]);

    }

    for (int i = n; i >= 1; i--) {

        R[i] = max(R[i + 1], b[i] - (C - x[i]));

    }

    for (int i = 1; i <= n; i++)

        ans = max(ans, L[i] + R[i + 1]);





    printf("%lld\n", ans);

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.5667597657920074x):
//### In The Name Of GOD ###



#include <bits/stdc++.h>



using namespace std;



typedef long long ll ;



const int MOD = 1000000007;

const int INF = 30 * 1000 + 20;

const int MAXN = 100 * 1000 + 20;

const int MLOG = 18;

const int NMAX = 60;



#define int ll

#define pb push_back

#define pp pop_back

#define X first

#define Y second

#define IO ios_base::sync_with_stdio(false);

#define sz(a) (int)(a.size())

#define ct(x) const_cast<const int&>(x)





int all[2];

int prf[2][MAXN];

int ap[2][MAXN];



signed main(){

	int n, ans = 0, C;

	cin >> n >> C;

	vector< pair<int,int> > vec[2];	

	vec[0].pb({0, 0});

	vec[1].pb({0, 0});

	for (int i = 0;i < n; i++){

		int x , v;

		cin >> x >> v;

		vec[0].pb({x, v});

		vec[1].pb({C-x,v});

	}

	sort(vec[0].begin(),vec[0].end());

	sort(vec[1].begin(),vec[1].end());

	for(int i = 1; i <= n; i++){

		prf[0][i] = prf[0][i-1] - vec[0][i].X + vec[0][i-1].X + vec[0][i].Y;

		ap[0][i] = max(ap[0][i-1], prf[0][i] - vec[0][i].X);

//		cout << ap[0][i]  << " 1 " << prf[0][i]  - vec[0][i].X << ' '  << endl;

	}

	for(int i = 1; i <= n; i++){

		prf[1][i] = prf[1][i-1] - vec[1][i].X + vec[1][i-1].X + vec[1][i].Y;

		ap[1][i] = max(ap[1][i-1], prf[1][i] - vec[1][i].X);

//	cout << ap[1][i]  << " 2 " << prf[1][i] << ' ' << endl;

}

	for(int i = 1; i <= n; i++){

		all[0] += -vec[0][i].X + vec[0][i-1].X + vec[0][i].Y;

		ans = max(ans, all[0] + ap[1][n-i]);

//		cout << all[0]  << " 3 " << vec[0][i].Y << ' ' << endl;

	}

//	cout << endl;

	for(int i = 1; i <= n; i++){

		all[1] += -vec[1][i].X + vec[1][i-1].X + vec[1][i].Y;

		ans = max(ans, all[1] + ap[0][n-i]);

//		cout << all[1]  << " 4 "  << vec[1][i].Y << ' ' << endl;

	}

	cout << ans;

}