#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
class RMQ {
 public:
  long long n, dat[555555];
  void init(int _n) {
    n = 1;
    while (n < _n) n *= 2;
    fill(dat, dat + 2 * n - 1, -MAXL);
  }
  void update(int k, long long a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  long long query(int a, int b) { return query(a, b, 0, 0, n); }
  long long query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return -MAXL;
    if (a <= l && r <= b) return dat[k];
    long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
RMQ t;
void Main() {
  long long n, m;
  cin >> n >> m;
  pair<long long, long long> a[n];
  for (long long i = (long long)(0); i < (long long)(n); i++)
    cin >> a[i].first >> a[i].second;
  long long d[2][n + 1], c[2][n + 1];
  memset(d, 0, sizeof(d)), memset(c, 0, sizeof(c));
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    d[0][i + 1] += a[i].first;
    c[0][i + 1] += c[0][i] + a[i].second;
  }
  for (long long i = (long long)(n)-1; i >= 0; i--) {
    d[1][i] += m - a[i].first;
    c[1][i] += c[1][i + 1] + a[i].second;
  }
  long long ans = 0;
  for (long long k = (long long)(0); k < (long long)(2); k++) {
    t.init(n + 1);
    for (long long i = (long long)(0); i < (long long)(n + 1); i++)
      t.update(i, c[k ^ 1][i] - d[k ^ 1][i]);
    for (long long i = (long long)(0); i < (long long)(n + 1); i++) {
      ans = max(ans, c[k][i] - d[k][i]);
      if (!k)
        ans = max(ans, c[k][i] - d[k][i] * 2 + t.query(i + 1, n + 1));
      else
        ans = max(ans, c[k][i] - d[k][i] * 2 + t.query(0, i));
    }
  }
  pr(ans);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
