#include <bits/stdc++.h>
using namespace std;
long long N, C, cal1, calt, cals;
long long x[100001], v[100001];
long long ori(int a) {
  int i;
  long long calte = -x[a] - (C - x[N]) + v[N],
            caltes = -x[a] - (C - x[N]) + v[N];
  for (i = N - 1; i > a; --i) {
    if ((x[i] - x[a]) * 2 >= C) {
      calte += v[i] - (x[i + 1] - x[i]);
      if (calte > caltes) {
        caltes = calte;
      }
    }
  }
  return caltes;
}
long long ori2(int a) {
  int i;
  long long calte = -(C - x[a]), caltes = -(C - x[a]);
  for (i = 1; i < a; ++i) {
    if ((x[a] - x[i]) * 2 >= C) {
      calte += v[i] - (x[i] - x[i - 1]);
      if (calte > caltes) {
        caltes = calte;
      }
    }
  }
  return caltes;
}
int main() {
  cin >> N >> C;
  int i;
  for (i = 1; i <= N; ++i) {
    cin >> x[i] >> v[i];
  }
  x[0] = 0;
  cal1 = 0;
  calt = 0;
  cals = 0;
  for (i = 1; i <= N; ++i) {
    cal1 += v[i] - (x[i] - x[i - 1]);
    if (v[i] > 2 * (x[i] - x[i - 1]) && x[i] * 2 <= C) {
      calt = ori(i) + cal1;
      if (calt > cals) {
        cals = calt;
      }
    }
    if (cal1 > cals) {
      cals = cal1;
    }
  }
  cal1 = v[N] - (C - x[N]);
  if (cal1 > cals) {
    cals = cal1;
  }
  if (v[N] > 2 * (C - x[N]) && x[N] * 2 >= C) {
    calt = ori2(N) + cal1;
    if (calt > cals) {
      cals = calt;
    }
  }
  for (i = N - 1; i > 0; --i) {
    cal1 += v[i] - (x[i + 1] - x[i]);
    if (v[i] > 2 * (x[i + 1] - x[i]) && x[i] * 2 >= C) {
      calt = ori2(i) + cal1;
      if (calt > cals) {
        cals = calt;
      }
    }
    if (cal1 > cals) {
      cals = cal1;
    }
  }
  cout << cals << endl;
  return 0;
}
