#include <bits/stdc++.h>
using namespace std;
int INF = 1e9;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
  }
  long long sum[100010] = {}, MAX = 0;
  for (int i = 0; i < n; i++) {
    sum[i] += v[i].second;
    MAX += v[i].second;
  }
  for (int i = 0; i < n - 1; i++) sum[i + 1] += sum[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      ans = max(ans, MAX + sum[i] - sum[j - 1] -
                         min((2 * v[i].first + c - v[j].first),
                             v[i].first + 2 * (c - v[j].first)));
    }
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, sum[i] - v[i].first);
  }
  cout << ans << endl;
}
