#include <bits/stdc++.h>
const int INF = 1e9;
const long long LLINF = 1e18;
using namespace std;
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long N, C;
long long x[100010];
long long v[100010];
long long sfd[100010], sbd[100010];
long long td;
int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    cin >> x[i + 1] >> v[i + 1];
  }
  td = 0LL;
  for (int i = 1; i < N + 1; i++) {
    td += v[i];
    if (i > 0) sfd[i] = max(0LL, sfd[i - 1]);
    sfd[i] = max(sfd[i], td - x[i]);
  }
  td = 0LL;
  for (int i = 1; i < N + 1; i++) {
    long long ii = N - i + 1;
    td += v[ii];
    if (i > 0) sbd[i] = max(0LL, sbd[i - 1]);
    sbd[i] = max(sbd[i], td - (C - x[ii]));
  }
  long long ans = 0;
  for (int start = 0; start < N + 1; start++) {
    long long sum1 = sfd[start];
    long long rmx1 = sbd[N - start] - x[start];
    if (rmx1 > 0) {
      sum1 += rmx1;
    }
    long long sum2 = sbd[start];
    long long rmx2 = sfd[N - start] - (C - x[start]);
    if (rmx2 > 0) {
      sum2 += rmx2;
    }
    ans = max({ans, sum1, sum2});
  }
  cout << ans << endl;
  return 0;
}
