#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
template <typename T, typename U>
bool chmin(T& a, const U& b) {
  return a > b ? (a = b, 1) : 0;
}
template <typename T, typename U>
bool chmax(T& a, const U& b) {
  return a < b ? (a = b, 1) : 0;
}
void print_vars(ostream&) {}
template <typename Car, typename... Cdr>
void print_vars(ostream& os, const Car& car, const Cdr&... cdr) {
  print_vars(os << car << (sizeof...(cdr) ? "," : ""), cdr...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <int I, typename Tuple>
void print_tuple(ostream&, const Tuple&) {}
template <int I, typename Car, typename... Cdr, typename Tuple>
void print_tuple(ostream& os, const Tuple& t) {
  os << get<I>(t) << (sizeof...(Cdr) ? "," : "");
  print_tuple<I + 1, Cdr...>(os, t);
}
template <typename... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  print_tuple<0, Args...>(os << '(', t);
  return os << ')';
}
template <typename Ch, typename Tr, typename C>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const C& c) {
  os << '[';
  for (auto i = begin(c); i != end(c); ++i)
    os << (i == begin(c) ? "" : " ") << *i;
  return os << ']';
}
constexpr ll INF = 1e18;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-9;
struct SegmentTree {
  using T = ll;
  const T data_unit = -INF;
  T Merge(T a, T b) { return max(a, b); }
  T Apply(T x, T d) { return x; }
  int NextPow2(int n) {
    n--;
    for (int i = 1; i < 32; i *= 2) n |= n >> i;
    return n + 1;
  }
  int size;
  vector<T> data;
  SegmentTree(int n) : size(NextPow2(n)), data(2 * size, data_unit) {}
  SegmentTree(const vector<T>& a)
      : size(NextPow2(a.size())), data(2 * size, data_unit) {
    copy(begin(a), end(a), begin(data) + size);
    for (int i = int(size); i-- > int(1);)
      data[i] = Merge(data[i * 2], data[i * 2 + 1]);
  }
  void PointUpdate(int i, T x) {
    data[size + i] = Apply(x, data[size + i]);
    for (i += size; i /= 2;) data[i] = Merge(data[i * 2], data[i * 2 + 1]);
  }
  T RangeQuery(int a, int b, int i, int l, int r) {
    if (b <= l || r <= a) return data_unit;
    if (a <= l && r <= b) return data[i];
    return Merge(RangeQuery(a, b, i * 2, l, (l + r) / 2),
                 RangeQuery(a, b, i * 2 + 1, (l + r) / 2, r));
  }
  T RangeQuery(int a, int b) { return RangeQuery(a, b, 1, 0, size); }
};
ll calc(ll n, ll c, vl xs, vl vs) {
  vl ss(n + 1), ts(n + 1);
  for (int i = int(0); i < int(n); i++) ss[i + 1] = ss[i] + vs[i];
  for (int i = int(0); i < int(n); i++) ss[i + 1] -= 2 * xs[i];
  for (int i = int(n); i-- > int(0);) ts[i] = ts[i + 1] + vs[i];
  SegmentTree st = ss;
  ll res = 0;
  for (int i = int(0); i < int(n); i++) {
    ll left = max(st.RangeQuery(0, i), 0ll);
    ll right = ts[i] - (c - xs[i]);
    chmax(res, left + right);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  constexpr char endl = '\n';
  for (ll n, c; cin >> n >> c && n | c;) {
    vl xs(n), vs(n);
    for (int i = int(0); i < int(n); i++) cin >> xs[i] >> vs[i];
    ll res = calc(n, c, xs, vs);
    reverse(begin(xs), end(xs));
    for (int i = int(0); i < int(n); i++) xs[i] = c - xs[i];
    reverse(begin(vs), end(vs));
    chmax(res, calc(n, c, xs, vs));
    cout << res << endl;
  }
}
