#include <bits/stdc++.h>
using namespace std;
struct poin {
  long long x;
  long long v;
} q[100005];
bool cmp(poin a, poin b) { return a.x < b.x; }
int main() {
  long long n, ans1 = 0, sum = 0, C, ans2 = 0, ans = 0, pos, dis;
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    cin >> q[i].x >> q[i].v;
  }
  sort(q, q + n, cmp);
  pos = -1;
  dis = 0;
  for (long long i = 0; i < n; i++) {
    sum += q[i].v;
    dis = q[i].v;
    if (sum - q[i].x > ans) {
      ans1 = sum - q[i].x;
      pos = i;
    }
  }
  sum = 0;
  for (long long i = n - 1; i > pos; i--) {
    sum += q[i].v;
    if (sum - (C - q[i].x) * 2 > ans2) ans2 = sum - (C - q[i].x) * 2;
  }
  if (ans < ans2 + ans1) ans = ans1 + ans2;
  ans1 = 0;
  ans2 = 0;
  sum = 0;
  pos = n;
  for (long long i = n - 1; i >= 0; i--) {
    sum += q[i].v;
    if (sum - (C - q[i].x) * 2 > ans2) {
      ans2 = sum - (C - q[i].x) * 2;
      pos = i;
    }
  }
  sum = 0;
  for (long long i = 0; i < pos; i++) {
    sum += q[i].v;
    if (sum - q[i].x > ans1) {
      ans1 = sum - q[i].x;
      pos = i;
    }
  }
  if (ans < ans2 + ans1) ans = ans1 + ans2;
  ans1 = 0;
  ans2 = 0;
  sum = 0;
  pos = -1;
  for (long long i = 0; i < n; i++) {
    sum += q[i].v;
    if (sum - 2 * q[i].x > ans1) {
      ans1 = sum - 2 * q[i].x;
      pos = i;
    }
  }
  sum = 0;
  for (long long i = n - 1; i > pos; i--) {
    sum += q[i].v;
    if (sum - (C - q[i].x) > ans2) ans2 = sum - (C - q[i].x);
  }
  if (ans < ans2 + ans1) ans = ans1 + ans2;
  ans1 = 0;
  ans2 = 0;
  sum = 0;
  pos = n;
  for (long long i = n - 1; i > 0; i--) {
    sum += q[i].v;
    if (sum - (C - q[i].x) > ans2) {
      ans2 = sum - (C - q[i].x);
      pos = i;
    }
  }
  sum = 0;
  for (long long i = 0; i < pos; i++) {
    sum += q[i].v;
    if (sum - 2 * q[i].x > ans1) {
      ans1 = sum - 2 * q[i].x;
    }
  }
  if (ans < ans2 + ans1) ans = ans1 + ans2;
  cout << ans << endl;
  return 0;
}
