#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 9e14;
struct edge {
  int to, cost;
};
long long int N, M, K, ans = 0;
long long int C;
long long int X[100010], V[100010];
long long int dis[100010], va[100010];
long long int rdis[100010], rva[100010];
unordered_map<long long int, long long int> Q;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> N >> C;
  for (int i = 0; i < signed(N); i++) {
    cin >> X[i] >> V[i];
    rdis[N - 1 - i] = C - X[i];
    dis[i] = X[i];
    rva[N - 1 - i] = va[i] = V[i];
  }
  for (int i = 0; i < signed(N); i++) {
    rva[i + 1] += rva[i];
    va[i + 1] += va[i];
  }
  for (int k = 0; k < signed(2); k++) {
    long long int temp = 0, buff = 0;
    if (k == 0) {
      for (int i = 0; i < signed(N); i++) {
        if (i == 0)
          temp = rva[N - 1] - rdis[N - 1] * 2;
        else {
          buff = max(buff, va[i - 1] - dis[i - 1]);
          temp = max(temp, rva[N - 1 - i] - rdis[N - 1 - i] * 2 + buff);
        }
      }
      ans = max({temp, va[N - 1] - dis[N - 1], ans});
    } else {
      for (int i = 0; i < signed(N); i++) {
        if (i == 0)
          temp = va[N - 1] - dis[N - 1] * 2;
        else {
          buff = max(buff, rva[i - 1] - rdis[i - 1]);
          temp = max(temp, va[N - 1 - i] - dis[N - 1 - i] * 2 + buff);
        }
      }
      ans = max({temp, rva[N - 1] - rdis[N - 1], ans});
    }
  }
  cout << ans << endl;
  return 0;
}
