#include <bits/stdc++.h>
const int MOD = 1000000007;
const int INF = 1000000000;
using namespace std;
int N;
long long C;
long long sushisum = 0;
long long Csushisum = 0;
long long ans = 0;
long long ans2 = 0;
long long x[100005];
long long v[100005];
long long f[100005];
long long g[100005];
long long B[100005];
long long A[100005];
long long Cf[100005];
long long Cg[100005];
int main(void) {
  cin >> N >> C;
  for (int i = 1; i <= N; ++i) {
    cin >> x[i] >> v[i];
  }
  for (int i = 0; i <= N + 1; i++) {
    sushisum += v[i];
    A[i] = sushisum - x[i];
    if (i == N + 1 || i == 0) A[i] = 0;
  }
  for (int i = N + 1; i >= 0; i--) {
    Csushisum += v[i];
    if (i == N + 1 || i == 0) {
      B[i] = 0;
    } else {
      B[i] = Csushisum - (C - x[i]);
    }
  }
  Csushisum = 0;
  sushisum = 0;
  for (int i = 0; i <= N; ++i) {
    sushisum += v[i];
    f[i] = sushisum - x[i];
  }
  for (int i = N + 1; i >= 0; i--) {
    Csushisum += v[i];
    if (i == N + 1 || i == 0) {
      Cf[i] = Csushisum;
    } else {
      Cf[i] = Csushisum - (C - x[i]);
    }
  }
  for (int i = 0; i <= N + 1; ++i) {
    if (i != 0 && i != N + 1) {
      g[i] = max(g[i - 1], f[i]);
    } else {
      g[i] = max(0LL, f[i]);
    }
  }
  for (int i = N + 1; i >= 0; i--) {
    if (i != N + 1 && i != 0) {
      Cg[i] = max(Cg[i + 1], Cf[i]);
    } else {
      Cg[i] = max(0LL, Cf[i]);
    }
  }
  for (int i = 0; i <= N; ++i) {
    if (i != 0) {
      if (g[i - 1] == 0) {
        ans = max(ans, B[i] + g[i - 1]);
      } else {
        ans = max(ans, B[i] + g[i - 1] - (C - x[i]));
      }
      if (Cg[i + 1] == 0) {
        ans2 = max(ans2, A[i] + Cg[i + 1]);
      } else {
        ans2 = max(ans2, A[i] + Cg[i + 1] - x[i]);
      }
    } else {
      ans = max(ans, 0LL);
      ans2 = max(ans2, 0LL);
    }
  }
  cout << max(ans, ans2) << endl;
  return 0;
}
