#include <bits/stdc++.h>
using namespace std;
struct Grid {
  int x, y, t;
};
struct Edge {
  int to, cost;
};
struct Graph {
  vector<vector<Edge>> E;
  int V;
  Graph(int n) : E(n) {
    E.resize(n);
    V = n;
  }
  void add_edge(int from, int to, int cost) {
    E[from - 1].push_back({to - 1, cost});
  }
};
long long sum[100010] = {};
class segTree {
 public:
  const long long Inf = 1e18;
  long long n = 0;
  vector<long long> node;
  segTree(long long nn) {
    n = 1;
    while (n < nn) n *= 2;
    node.resize(n * 2);
    init(-Inf);
  }
  void init(long long hoge) {
    for (int i = 0; i < node.size(); i++) node[i] = hoge;
  }
  void init(vector<long long> hoge) {
    for (int i = 0; i < hoge.size(); i++) update(i, hoge[i]);
  }
  void update(int index, const long long value) {
    index += n;
    node[index] = value;
    while (index > 0) {
      index /= 2;
      node[index] = ope(node[2 * index], node[2 * index + 1]);
    }
  }
  long long find(int l, int r) {
    if (l == r) return node[r + n];
    l += n;
    r += n;
    long long ans = -Inf;
    for (; l <= r; l >>= 1, r >>= 1) {
      if (r == l) {
        ans = ope(ans, node[l]);
        return ans;
      }
      if (r % 2 == 0) ans = ope(ans, node[r]), --r;
      if (l % 2) ans = ope(ans, node[l]), ++l;
    }
    return ans;
  }
  long long ope(const long long a, const long long b) { return max(a, b); }
};
int main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> le(n + 10), ri(n + 10);
  vector<long long> pll(n);
  vector<long long> pl(n);
  for (int i = 0; i < n; i++) {
    cin >> pll[i] >> pl[i];
    le[i + 1] = pl[i] + le[i];
  }
  for (int i = n; i > 0; i--) {
    ri[i] = ri[i + 1] + pl[i - 1];
  }
  segTree seg(n + 5), seg3(n + 5);
  for (int i = 1; i <= n; i++) {
    seg.update(i - 1, le[i] - pll[i - 1]);
    seg3.update(i - 1, ri[i] - (c - pll[i - 1]));
  }
  for (int i = 0; i < n; i++) {
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, le[i + 1] - 2 * pll[i] + max(0LL, seg3.find(i + 1, n - 1)));
    ans = max(ans, ri[i + 1] - 2 * (c - pll[i]) + max(seg.find(0, i - 1), 0LL));
  }
  cout << ans << endl;
  return 0;
}
