#include <bits/stdc++.h>
using namespace std;
const long long LLINF = (1LL << 60);
const long long INF = (1LL << 30);
const long long MOD = 1000000007;
long long N, C;
long long X[100010] = {};
long long V[100010] = {};
template <typename T>
class CumulativeSum {
 public:
  vector<T> m_data;
  CumulativeSum(){};
  CumulativeSum(long long sz) : m_data(sz, 0){};
  void Add(long long k, long long x) {
    assert(m_data.size() >= k);
    if (m_data.size() <= k) {
      m_data.push_back(x);
    } else {
      m_data[k] += x;
    }
  }
  void Build() {
    for (long long i = 1; i < m_data.size(); i++) {
      m_data[i] += m_data[i - 1];
    }
  }
  T Query(long long k) {
    if (k < 0) {
      return 0;
    }
    return (m_data[min(k, (long long)m_data.size() - 1)]);
  }
  T Query(long long l, long long h) {
    return this->Query(h) - this->Query(l - 1);
  }
};
signed main() {
  CumulativeSum<long long> cs;
  cin >> N >> C;
  for (long long i = 0; i < N; ++i) {
    cin >> X[i] >> V[i];
    cs.Add(i, V[i]);
  }
  cs.Build();
  long long cw = 0;
  for (long long i = 0; i < N; ++i) {
    long long cal = cs.Query(0, i) - X[i];
    cw = max(cw, cal);
  }
  long long ccw = 0;
  for (long long i = N - 1; i >= 0; --i) {
    long long cal = cs.Query(i, N - 1) - (C - X[i]);
    ccw = max(ccw, cal);
  }
  long long cw_half_r = 0;
  long long cw_half_r_ind = -1;
  for (long long i = 0; i < N; ++i) {
    if (X[i] >= C / 2) {
      break;
    }
    long long cal = cs.Query(0, i) - X[i] * 2;
    if (cw_half_r < cal) {
      cw_half_r = cal;
      cw_half_r_ind = i;
    }
  }
  long long ccw_half_r = 0;
  long long ccw_half_r_ind = -1;
  for (long long i = N - 1; i >= 0; --i) {
    if (X[i] <= C / 2) {
      break;
    }
    long long cal = cs.Query(i, N - 1) - (C - X[i]) * 2;
    if (ccw_half_r < cal) {
      ccw_half_r = cal;
      ccw_half_r_ind = i;
    }
  }
  long long cw_half = 0;
  if (ccw_half_r_ind >= 0) {
    for (long long i = 0; i < N; ++i) {
      if (i == ccw_half_r_ind) {
        break;
      }
      long long cal = cs.Query(0, i) - X[i];
      cw_half = max(cw_half, cal);
    }
  }
  long long ccw_half = 0;
  if (cw_half_r_ind >= 0) {
    for (long long i = N - 1; i >= 0; --i) {
      if (i == cw_half_r_ind) {
        break;
      }
      long long cal = cs.Query(i, N - 1) - (C - X[i]);
      ccw_half = max(ccw_half, cal);
    }
  };
  ;
  ;
  ;
  ;
  ;
  long long ans = max({cw, ccw, cw_half_r + ccw_half, ccw_half_r + cw_half});
  printf("%lld\n", ans);
  return 0;
}
