#include <bits/stdc++.h>
using namespace std;
struct XX {
  long long la;
  long long lb;
  long long ra;
  long long rb;
  long long q;
};
class xxGreater {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.q) == (riRight.q)) {
      return riLeft.q < riRight.q;
    }
    return (riLeft.q) < (riRight.q);
  }
};
int asum(string P) {
  int sum = 0;
  int strength = 1;
  for (int i = 0; i < P.size(); i++) {
    if (P.substr(i, 1) == "S") {
      sum += strength;
    } else {
      strength *= 2;
    }
  }
  return sum;
}
int n;
int dat[2 * 100];
int dat2[2 * 100];
void init(int n_) {
  n = 1;
  while (n < n_) n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    dat[i] = 0;
    dat2[i] = 0;
  }
}
void initset(int k, int a) {
  k += n - 1;
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
  }
}
void update2(int a, int b, int k, int l, int r, int v) {
  if (r <= a || b <= l) return;
  if (a <= l && r <= b) {
    dat[k] += dat2[k];
    if (r - l > 1) {
      dat2[k * 2 + 1] += dat2[k] / 2;
      dat2[k * 2 + 1] += dat2[k] / 2;
    }
    dat2[k] = v * (r - l);
    return;
  } else {
    update2(a, b, k * 2 + 1, l, (l + r) / 2, v);
    update2(a, b, k * 2 + 2, (l + r) / 2, r, v);
    return;
  }
}
int query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) {
    dat[k] += dat2[k];
    if (r - l > 1) {
      dat2[k * 2 + 1] += dat2[k] / 2;
      dat2[k * 2 + 1] += dat2[k] / 2;
    }
    dat2[k] = 0;
    return dat[k];
  } else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return vl + vr;
  }
}
int dp[10005][10005];
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, C;
  cin >> N >> C;
  long long x[100000];
  long long y[100000];
  long long v[100000];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }
  for (int i = 0; i < N; i++) {
    y[i] = C - x[i];
  }
  long long ans = 0;
  long long sum = 0;
  long long kyori = 0;
  long long kyori2 = 0;
  for (int p = 0; p < N; p++) {
    sum = 0;
    kyori = 0;
    kyori2 = 0;
    for (int i = 0; i < p; i++) {
      sum += v[N - 1 - i];
      kyori = y[N - 1 - i];
      ans = max(ans, sum - kyori);
    }
    kyori *= 2;
    for (int i = 0; i < N - p; i++) {
      sum += v[i];
      kyori2 = x[i];
      ans = max(ans, sum - kyori - kyori2);
    }
  }
  for (int p = 0; p < N; p++) {
    sum = 0;
    kyori = 0;
    kyori2 = 0;
    for (int i = 0; i < p; i++) {
      sum += v[i];
      kyori2 = x[i];
      ans = max(ans, sum - kyori2);
    }
    kyori2 *= 2;
    for (int i = 0; i < N - p; i++) {
      sum += v[N - 1 - i];
      kyori = y[N - 1 - i];
      ans = max(ans, sum - kyori - kyori2);
    }
  }
  cout << ans << endl;
  return 0;
}
