#include <bits/stdc++.h>
using namespace std;
struct Seg {
 public:
  int n;
  vector<long long> seg;
  long long INF;
  void init(long long x) {
    n = 1;
    INF = -700000000000000000;
    while (n < x) n *= 2;
    seg.resize(n * 2 + 1);
    for (int i = 0; i < n * 2; i++) seg[i] = INF;
  }
  void update(int i, long long x) {
    int now = i + n - 1;
    seg[now] = max(seg[now], x);
    while (now > 0) {
      now = (now - 1) / 2;
      seg[now] = max(seg[now * 2 + 1], seg[now * 2 + 2]);
    }
  }
  long long find(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
      return INF;
    else if (a <= l && r <= b)
      return seg[k];
    else {
      long long v1, v2;
      v1 = find(a, b, k * 2 + 1, l, (l + r) / 2);
      v2 = find(a, b, k * 2 + 2, (l + r) / 2, r);
      return max(v1, v2);
    }
  }
};
long long n, c;
long long x[111111], v[111111];
long long r1[111111], r2[111111];
long long ans = 0;
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> x[i] >> v[i];
  Seg a, b;
  a.init(111111);
  b.init(111111);
  long long cost = 0, dist = 0;
  for (int i = 0; i < n; i++) {
    cost += v[i], dist = x[i];
    a.update(i, cost - dist);
    r1[i] = cost - dist;
  }
  cost = 0, dist = 0;
  for (int i = n - 1; i >= 0; i--) {
    cost += v[i], dist = c - x[i];
    b.update((n - 1) - i, cost - dist);
    r2[i] = cost - dist;
  }
  long long ret;
  for (int i = 0; i < n; i++) {
    ans = max(ans, r1[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    ans = max(ans, r2[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    ret = 0;
    ret += r1[i];
    ret -= x[i];
    int l = n - 1, r = i + 1;
    l = (n - 1) - l, r = (n - 1) - r;
    long long c = b.find(l, r, 0, 0, b.n);
    ret += c;
    ans = max(ans, ret);
  }
  for (int i = n - 1; i > 0; i--) {
    ret = 0;
    ret += r2[i];
    ret -= (c - x[i]);
    int l = 0, r = i - 1;
    long long c = a.find(l, r, 0, 0, a.n);
    ret += c;
    ans = max(ans, ret);
  }
  cout << ans << endl;
  return 0;
}
