#include <bits/stdc++.h>
using namespace std;
long power(long base, long exponent, long mod) {
  if (exponent % 2) {
    return power(base, exponent - 1, mod) * base % mod;
  } else if (exponent) {
    long root_ans = power(base, exponent / 2, mod);
    return root_ans * root_ans % mod;
  } else {
    return 1;
  }
}
struct sushi {
  long position, calorie;
};
int main() {
  int N;
  long C;
  cin >> N >> C;
  sushi sushis[N + 2];
  sushis[0] = {0, 0};
  sushis[N + 1] = {C, 0};
  for (int i = 1; i <= N; i++) {
    cin >> sushis[i].position >> sushis[i].calorie;
  }
  long ans = 0;
  for (int i = 0; i < N + 2; i++) {
    for (int j = i + 1; j < N + 2; j++) {
      long this_ans = -(sushis[i].position + (C - sushis[j].position) +
                        min(sushis[i].position, C - sushis[j].position));
      for (int k = 0; k < N + 2; k++) {
        if (k <= i || k >= j) {
          this_ans += sushis[k].calorie;
        }
      }
      ans = max(ans, this_ans);
    }
  }
  cout << ans << endl;
}
