#include <bits/stdc++.h>
using namespace std;
int N;
long long C;
long long x, v;
vector<pair<long long, long long> > sushi;
long long ans;
long long walk;
long long sushi_cal;
int main() {
  cin >> N >> C;
  for (int i = 0; i < N; ++i) {
    cin >> x >> v;
    sushi.push_back(make_pair(x, v));
  }
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; i + j <= N; ++j) {
      walk = sushi_cal = 0;
      if (i != 0 && j != 0) {
        long long clockwise = sushi[i - 1].first;
        long long ct_clockwise = C - sushi[N - j].first;
        walk = clockwise + ct_clockwise + min(clockwise, ct_clockwise);
      } else if (i == 0 && j != 0) {
        walk = C - sushi[N - j].first;
      } else if (i != 0 && j == 0) {
        walk = sushi[i - 1].first;
      } else
        walk = 0;
      for (int k = 0; k < i; ++k) {
        sushi_cal += sushi[k].second;
      }
      for (int k = N - 1; k >= N - j; --k) {
        sushi_cal += sushi[k].second;
      }
      ans = max(ans, sushi_cal - walk);
    }
  }
  cout << ans << endl;
}
