#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long> > s(n + 2);
  s[0] = make_pair(0, 0);
  s[n + 1] = make_pair(c, 0);
  for (int i = 1; i <= n; i++) {
    cin >> s[i].first;
    cin >> s[i].second;
  }
  long long ans = 0;
  long long v = 0;
  for (int i = 1; i <= n; i++) v += s[i].second;
  long long minv = 1000000000000000000LL, cur;
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n + 1; j++) {
      cur = 0;
      for (int l = i + 1; l <= j - 1; l++) cur += s[l].second;
      cur += min(s[i].first, c - s[j].first) + c - s[j].first + s[i].first;
      minv = min(minv, cur);
    }
  }
  ans = max(0LL, v - minv);
  cout << ans;
}
