#include <bits/stdc++.h>
using namespace std;
template <typename T>
static ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename F, typename S>
static istream& operator>>(istream& stream, pair<F, S>& t) {
  return stream >> t.first >> t.second;
}
template <typename T>
static istream& read(T, T, istream& = cin);
template <typename T>
static istream& operator>>(istream& stream, vector<T>& t) {
  return read((t).begin(), (t).end(), stream);
}
template <typename T>
static istream& read(T b, T e, istream& stream) {
  for (T it = b; it != e; ++it) stream >> *it;
  return stream;
}
struct _print {
  string sep, end;
  bool space;
  ostream& stream;
  _print(string _sep = " ", string _end = "\n", ostream& _stream = cout)
      : sep(_sep), end(_end), space(false), stream(_stream) {}
  ~_print() { stream << end; }
  template <typename T>
  _print& operator,(const T& t) {
    if (space) stream << sep;
    space = true;
    stream << t;
    return *this;
  }
};
void __() {
  long long n;
  cin >> n;
  long long c;
  cin >> c;
  vector<pair<long long long long> >(a, n);
  cin >> long long >> ;
  n += 2;
  a.insert(a.begin(), {0, 0});
  a.push_back({c, 0});
  vector<long long> pl(n), pr(n);
  vector<long long> l2(n), r2(n);
  for (int i = 0; i < n; ++i) pl[i] = a[i].second + (i > 0 ? pl[i - 1] : 0);
  for (int i = n - 1; i >= 0; --i)
    pr[i] = a[i].second + (i < n - 1 ? pr[i + 1] : 0);
  for (int i = n - 1; i >= 0; --i) {
    r2[i] = -2 * (c - a[i].first) + pr[i];
    if (i + 1 < n && r2[i + 1] > r2[i]) r2[i] = r2[i + 1];
    r2[i] = max(r2[i], 0ll);
  }
  for (int i = 0; i < n; ++i) {
    l2[i] = -2 * (a[i].first) + pl[i];
    if (i && l2[i - 1] > l2[i]) l2[i] = l2[i - 1];
    l2[i] = max(l2[i], 0ll);
  }
  long long ans = 0;
  for (int i = 0; i < n - 2; ++i) {
    ans = max(ans, pl[i] - a[i].first + r2[i + 1]);
  }
  for (int i = 1; i <= n - 1; ++i) {
    ans = max(ans, pr[i] - (c - a[i].first) + l2[i - 1]);
  }
  _print(), ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  __();
}
