#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
long long dist[MAXN];
long long nut[MAXN];
int main() {
  int n;
  cin >> n;
  long long c;
  cin >> c;
  vector<pair<long long, long long> > v(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin() + 1, v.end());
  for (int i = 1; i <= n; ++i) {
    dist[i] = v[i].first;
    nut[i] = nut[i - 1] + v[i].second;
  }
  long long best = 0;
  for (int i = 1; i <= n; ++i) {
    best = max(best, max(nut[i] - dist[i], nut[n] - nut[i - 1] - c + dist[i]));
  }
  cout << best;
  return 0;
}
