#include <bits/stdc++.h>
using namespace std;
long power(long base, long exponent, long mod) {
  if (exponent % 2) {
    return power(base, exponent - 1, mod) * base % mod;
  } else if (exponent) {
    long root_ans = power(base, exponent / 2, mod);
    return root_ans * root_ans % mod;
  } else {
    return 1;
  }
}
struct sushi {
  long position, calorie;
  bool operator<(const long &another) const { return position < another; }
  bool operator>(const long &another) const { return position > another; }
};
signed main() {
  int N;
  long C;
  cin >> N >> C;
  vector<sushi> sushis[2];
  sushi sushis_array[N];
  sushis[1].push_back({C, 0});
  long ans = -C;
  for (int i = 0; i < N; i++) {
    cin >> sushis_array[i].position >> sushis_array[i].calorie;
    if (sushis_array[i].position * 2 <= C) {
      sushis[0].push_back(sushis_array[i]);
    } else {
      sushis[1].push_back(
          {C - sushis_array[i].position, sushis_array[i].calorie});
    }
    ans += sushis_array[i].calorie;
  }
  sushis[1].push_back({0, 0});
  reverse((sushis[1]).begin(), (sushis[1]).end());
  ans = max(ans, 0l);
  long sushi_cumulative_sum = 0;
  for (int i = 0; i < N; i++) {
    sushi_cumulative_sum += sushis_array[i].calorie;
    ans = max(ans, sushi_cumulative_sum - sushis_array[i].position);
  }
  sushi_cumulative_sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    sushi_cumulative_sum += sushis_array[i].calorie;
    ans = max(ans, sushi_cumulative_sum - (C - sushis_array[i].position));
  }
  long sushi_cumulative_sum_1 = 0, sushi_cumulative_sums_1[sushis[1].size()];
  for (int i = 0; i < sushis[1].size(); i++) {
    sushi_cumulative_sum_1 += sushis[1][i].calorie;
    sushi_cumulative_sums_1[i] = sushi_cumulative_sum_1;
  }
  long sushi_cumulative_sums_1_double_max = 0,
       sushi_cumulative_sums_1_double_maxs[sushis[1].size()];
  for (int i = 0; i < sushis[1].size(); i++) {
    sushi_cumulative_sums_1_double_max =
        max(sushi_cumulative_sums_1_double_max,
            sushi_cumulative_sums_1[i] - sushis[1][i].position * 2);
    sushi_cumulative_sums_1_double_maxs[i] = sushi_cumulative_sums_1_double_max;
  }
  long sushi_cumulative_sums_1_single_max = 0,
       sushi_cumulative_sums_1_single_maxs[sushis[1].size()];
  for (int i = int(sushis[1].size()) - 1; i >= 0; i--) {
    sushi_cumulative_sums_1_single_max =
        max(sushi_cumulative_sums_1_single_max,
            sushi_cumulative_sums_1[i] - sushis[1][i].position);
    sushi_cumulative_sums_1_single_maxs[i] = sushi_cumulative_sums_1_single_max;
  }
  long sushi_cumulative_sum_0 = 0;
  for (int i = 0; i < sushis[0].size(); i++) {
    sushi_cumulative_sum_0 += sushis[0][i].calorie;
    ans = max(ans, sushi_cumulative_sum_0 - sushis[0][i].position +
                       sushi_cumulative_sums_1_double_maxs
                           [lower_bound((sushis[1]).begin(), (sushis[1]).end(),
                                        sushis[0][i].position) -
                            sushis[1].begin() - 1]);
    ans = max(ans, sushi_cumulative_sum_0 - sushis[0][i].position * 2 +
                       sushi_cumulative_sums_1_single_maxs
                           [lower_bound((sushis[1]).begin(), (sushis[1]).end(),
                                        sushis[0][i].position) -
                            sushis[1].begin()]);
  }
  cout << ans << endl;
}
