#include <bits/stdc++.h>
using namespace std;
int bitcnt(long long x) {
  x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
  x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
  x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
  x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
  x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
  x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
  return x;
}
int bitcnt(int x) {
  x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
  x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
  x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
  x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
  x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
  return x;
}
long long sqrt(long long x) {
  long long left = 0, right = x;
  for (int i = 0; i < (int)100; i++) {
    long long mid = (left + right) >> 1;
    if (mid * mid <= x)
      left = mid;
    else
      right = mid;
  }
  return left;
}
long long gcd(long long a, long long b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long double eps = 1e-15;
const int dx[] = {1, 0, -1, 0, 0};
const int dy[] = {0, 1, 0, -1, 0};
int main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  for (int i = 0; i < (int)n; i++) cin >> x[i] >> v[i];
  x.insert(x.begin(), 0);
  v.insert(v.begin(), 0);
  vector<long long> cw(n + 1);
  vector<pair<long long, long long> > cwmax(n + 1);
  for (int i = 1; i <= (int)n; i++) {
    cw[i] = -x[i] + x[i - 1] + v[i] + cw[i - 1];
    cwmax[i] = max(make_pair(cw[i], x[i]), cwmax[i - 1]);
  }
  vector<long long> ccw(n + 1);
  vector<pair<long long, long long> > ccwmax(n + 1);
  for (int i = n; i > 0; i--) {
    ccw[i] =
        -(x[(i + 1) % (n + 1)] - x[i] + c) % c + v[i] + ccw[(i + 1) % (n + 1)];
    ccwmax[i] = max(make_pair(ccw[i], c - x[i]), ccwmax[(i + 1) % (n + 1)]);
  }
  long long ret = 0;
  for (int i = 0; i <= (int)n; i++) {
    ret = max(ret, ccwmax[(i + 1) % (n + 1)].first -
                       ccwmax[(i + 1) % (n + 1)].second + cw[i]);
    ret = max(ret, cwmax[(i + n) % (n + 1)].first -
                       cwmax[(i + n) % (n + 1)].second + ccw[i]);
  }
  cout << ret << endl;
  return 0;
}
