#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
int main() {
  ios::sync_with_stdio(false);
  int N;
  long long C;
  cin >> N >> C;
  vector<pair<int, int> > sushi(N);
  for (int i = 0; i < (int)(N); i++) {
    cin >> sushi[i].first >> sushi[i].second;
  }
  long long ans = 0LL;
  long long tmp = 0LL;
  for (int i = 0; i < N; i++) {
    tmp += sushi[i].second;
    ans = max(ans, tmp - sushi[i].first);
  }
  tmp = 0LL;
  for (int i = N - 1; i >= 0; i--) {
    tmp += sushi[i].second;
    ans = max(ans, tmp - (C - sushi[i].first));
  }
  cout << ans << endl;
}
