#include <bits/stdc++.h>
using namespace std;
const int INF = (0x7FFFFFFFL);
const long long INFF = (0x7FFFFFFFFFFFFFFFL);
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int MOD = 1e9 + 7;
const int MODD = 998244353;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1.0);
const double EPS = 1e-9;
const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int dy[9] = {0, 1, 0, -1, -1, -1, 1, 1, 0};
template <typename T>
void MACRO_VAR_Scan(T &t) {
  cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
  cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <class T>
ostream &operator<<(ostream &o, const vector<T> &j) {
  o << "{";
  for (int i = 0; i < (int)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i];
  o << "}";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &j) {
  o << "{" << j.first << ", " << j.second << "}";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &j) {
  o << "{";
  for (auto t = j.begin(); t != j.end(); ++t)
    o << (t != j.begin() ? ", " : "") << *t;
  o << "}";
  return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T> &j) {
  o << "{";
  for (auto t = j.begin(); t != j.end(); ++t)
    o << (t != j.begin() ? ", " : "") << *t;
  o << "}";
  return o;
}
inline void print(void) { cout << endl; }
template <class Head>
void print(Head &&head) {
  cout << head;
  print();
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head << " ";
  print(forward<Tail>(tail)...);
}
inline void debug(void) { cerr << endl; }
template <class Head>
void debug(Head &&head) {
  cerr << head;
  debug();
}
template <class Head, class... Tail>
void debug(Head &&head, Tail &&...tail) {
  cerr << head << " ";
  debug(forward<Tail>(tail)...);
}
template <typename T>
void PA(T &a) {
  int ASIZE = sizeof(a) / sizeof(a[0]);
  for (int ii = 0; ii < ASIZE; ++ii) {
    cout << a[ii] << " \n"[ii == ASIZE - 1];
  }
}
template <typename T>
void PV(T &v) {
  int VSIZE = v.size();
  for (int ii = 0; ii < VSIZE; ++ii) {
    cout << v[ii] << " \n"[ii == VSIZE - 1];
  }
}
inline void YES(bool x) { cout << ((x) ? "YES" : "NO") << endl; }
inline void Yes(bool x) { cout << ((x) ? "Yes" : "No") << endl; }
inline void yes(bool x) { cout << ((x) ? "yes" : "no") << endl; }
inline void yES(bool x) { cout << ((x) ? "yES" : "nO") << endl; }
inline void Yay(bool x) { cout << ((x) ? "Yay!" : ":(") << endl; }
template <typename A, typename B>
void sankou(bool x, A a, B b) {
  cout << ((x) ? (a) : (b)) << endl;
}
inline long long MOP(long long x, long long n, long long m = MOD) {
  long long r = 1;
  while (n > 0) {
    if (n & 1) (r *= x) %= m;
    (x *= x) %= m;
    n >>= 1;
  }
  return r;
}
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
inline long long POW(long long a, long long b) {
  long long c = 1ll;
  do {
    if (b & 1) c *= 1ll * a;
    a *= 1ll * a;
  } while (b >>= 1);
  return c;
}
template <typename T>
inline bool between(T x, T a, T b) {
  return ((a <= x) && (x < b));
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <typename A, typename B>
inline bool chmax(A &a, const B &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, const B &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct abracadabra {
  abracadabra() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} ABRACADABRA;
signed main() {
  long long N, C;
  MACRO_VAR_Scan(N, C);
  ;
  vector<long long> X, V;
  for (long long i = long long(0); i < long long(N); ++i) {
    long long x, v;
    MACRO_VAR_Scan(x, v);
    ;
    X.push_back(x);
    V.push_back(v);
  }
  vector<long long> clo_dst, ant_dst;
  clo_dst.push_back(0);
  ant_dst.push_back(0);
  for (long long i = long long(0); i < long long(N); ++i) {
    clo_dst.push_back(X[i]);
    ant_dst.push_back(C - X[N - 1 - i]);
  }
  vector<long long> clo_cal, ant_cal;
  clo_cal.push_back(0);
  ant_cal.push_back(0);
  for (long long i = long long(0); i < long long(N); ++i) {
    clo_cal.push_back(clo_cal[i] + V[i]);
    ant_cal.push_back(ant_cal[i] + V[N - 1 - i]);
  }
  vector<long long> clo_get, ant_get;
  for (long long i = long long(0); i < long long(N + 1); ++i) {
    clo_get.push_back(clo_cal[i] - clo_dst[i]);
    ant_get.push_back(ant_cal[i] - ant_dst[i]);
  }
  {
    cerr << "clo_get"
         << " : ";
    for (const auto &xxx : clo_get) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "ant_get"
         << " : ";
    for (const auto &xxx : ant_get) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  vector<long long> clo_dbl, ant_dbl;
  for (long long i = long long(0); i < long long(N + 1); ++i) {
    clo_dbl.push_back(clo_cal[i] - clo_dst[i] * 2);
    ant_dbl.push_back(ant_cal[i] - ant_dst[i] * 2);
  }
  {
    cerr << "clo_dbl"
         << " : ";
    for (const auto &xxx : clo_dbl) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "ant_dbl"
         << " : ";
    for (const auto &xxx : ant_dbl) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  long long res = 0;
  vector<long long> ant_dbl_max;
  ant_dbl_max.push_back(ant_dbl[0]);
  for (long long i = long long(0); i < long long(N); ++i)
    ant_dbl_max.push_back(max(ant_dbl_max[i], ant_dbl[i + 1]));
  {
    cerr << "ant_dbl_max"
         << " : ";
    for (const auto &xxx : ant_dbl_max) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  for (long long i = long long(0); i < long long(N); ++i)
    chmax(res, clo_get[i] + ant_dbl_max[N - i]);
  vector<long long> clo_dbl_max;
  clo_dbl_max.push_back(clo_dbl[0]);
  for (long long i = long long(0); i < long long(N); ++i)
    clo_dbl_max.push_back(max(clo_dbl_max[i], clo_dbl[i + 1]));
  {
    cerr << "clo_dbl_max"
         << " : ";
    for (const auto &xxx : clo_dbl_max) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  for (long long i = long long(0); i < long long(N); ++i)
    chmax(res, ant_get[i] + clo_dbl_max[N - i]);
  print(res);
}
