#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const long long INFF = 1e18;
const long long INTMAX = (0x7FFFFFFFL);
const long long LLMAX = (0x7FFFFFFFFFFFFFFFL);
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;
}
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)...);
}
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 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;
}
inline long long bit(long long x) { return (1ll << x); }
inline bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;
  for (int i = 3; i <= sqrt(x) + 1; i += 2)
    if (x % i == 0) return false;
  return true;
}
inline vector<bool> Eratosthenes(const int n) {
  vector<bool> r(n + 1, true);
  for (int i = 2; i * i <= n; ++i) {
    if (r[i]) {
      for (int j = i * 2; j <= n; j += i) r[j] = false;
    }
  }
  if (r.size() > 2) {
    r[0] = 0;
    r[1] = 0;
  } else if (r.size() > 1) {
    r[0] = 0;
  }
  return r;
}
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;
}
inline long long digitsum(long long x) {
  long long d;
  long long r = 0;
  while (x) {
    d = x % 10;
    r += d;
    x /= 10;
  }
  return r;
}
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;
}
const int MAX_N = 2020202;
long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = long long(2); i < long long(MAX_N); ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long nCr(long long n, long long r) {
  if (r < 0 || n < r)
    return 0;
  else
    return (fac[n] * ((finv[n - r] * finv[r]) % MOD)) % MOD;
}
long long nPr(long long n, long long r) {
  if (r < 0 || n < r)
    return 0;
  else
    return (fac[n] * finv[n - r]) % MOD;
}
long long nHr(long long n, long long r) {
  if (n == 0 && r == 0)
    return 1;
  else
    return nCr(n + r - 1, r);
}
inline long long toInt(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <typename T>
inline void ntos(const T &n, string &s) {
  stringstream stream;
  stream << n;
  stream >> s;
}
template <typename T>
inline void ston(const string &s, T &n) {
  stringstream stream(s);
  stream >> n;
}
bool SORT_PAIR_SECOND(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
struct UnionFind {
  vector<int> parent;
  int __size;
  UnionFind(int size_) : parent(size_, -1), __size(size_) {}
  void unite(int x, int y) {
    if ((x = find(x)) != (y = find(y))) {
      if (parent[y] < parent[x]) swap(x, y);
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
  int size(int x) { return -parent[find(x)]; }
  int size() { return __size; }
};
using Weight = int;
using Flow = int;
struct Edge {
  int src, dst;
  Weight weight;
  Flow cap;
  Edge() : src(0), dst(0), weight(0) {}
  Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
  g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
  g[a].emplace_back(a, b, w);
}
Matrix WarshallFloyd(const Graph &g) {
  auto const INF = std::numeric_limits<Weight>::max() / 8;
  int n = g.size();
  Matrix d(n, Array(n, INF));
  for (long long i = long long(0); i < long long(n); ++i) d[i][i] = 0;
  for (long long i = long long(0); i < long long(n); ++i)
    for (auto &e : g[i]) d[e.src][e.dst] = min(d[e.src][e.dst], e.weight);
  for (long long k = long long(0); k < long long(n); ++k)
    for (long long i = long long(0); i < long long(n); ++i)
      for (long long j = long long(0); j < long long(n); ++j)
        if (d[i][k] != INF && d[k][j] != INF)
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  return d;
}
vector<Weight> Dijkstra(const Graph &g, int s) {
  const Weight INF = numeric_limits<Weight>::max() / 8;
  using state = tuple<Weight, int>;
  priority_queue<state> q;
  vector<Weight> dist(g.size(), INF);
  dist[s] = 0;
  q.emplace(0, s);
  while (q.size()) {
    Weight d;
    int v;
    tie(d, v) = q.top();
    q.pop();
    d *= -1;
    if (dist[v] < d) continue;
    for (auto &e : g[v]) {
      if (dist[e.dst] > dist[v] + e.weight) {
        dist[e.dst] = dist[v] + e.weight;
        q.emplace(-dist[e.dst], e.dst);
      }
    }
  }
  return dist;
}
struct abracadabra {
  abracadabra() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} ABRACADABRA;
vector<long long> X, Y, V;
signed main() {
  long long N, C;
  MACRO_VAR_Scan(N, C);
  ;
  X.push_back(0);
  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);
  }
  Y.push_back(0);
  for (long long i = long long(N); i >= long long(1); --i) {
    Y.push_back(C - X[i]);
  }
  vector<long long> clockwise, anticwise;
  clockwise.push_back(0);
  anticwise.push_back(0);
  for (long long i = long long(0); i < long long(N); ++i) {
    clockwise.push_back(clockwise[i] - (X[i + 1] - X[i]) + V[i]);
    anticwise.push_back(anticwise[i] - (Y[i + 1] - Y[i]) + V[N - 1 - i]);
  }
  vector<long long> clockdist, anticdist;
  for (long long i = long long(0); i < long long(N + 1); ++i) {
    clockdist.push_back(clockwise[i] - X[i]);
    anticdist.push_back(anticwise[i] - Y[i]);
  }
  long long res = 0;
  for (long long i = long long(0); i < long long(N + 1); ++i) {
    long long cal1 = clockdist[i] +
                     *max_element(anticwise.begin(), anticwise.begin() + N - i);
    long long cal2 = clockwise[i];
    chmax(res, max(cal1, cal2));
  }
  for (long long i = long long(0); i < long long(N + 1); ++i) {
    long long cal1 = anticdist[i] +
                     *max_element(clockwise.begin(), clockwise.begin() + N - i);
    long long cal2 = anticwise[i];
    chmax(res, max(cal1, cal2));
  }
  print(res);
  {
    cerr << "clockwise"
         << " : ";
    for (const auto &xxx : clockwise) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "anticwise"
         << " : ";
    for (const auto &xxx : anticwise) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "clockdist"
         << " : ";
    for (const auto &xxx : clockdist) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "anticdist"
         << " : ";
    for (const auto &xxx : anticdist) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "X"
         << " : ";
    for (const auto &xxx : X) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
  {
    cerr << "Y"
         << " : ";
    for (const auto &xxx : Y) {
      cerr << xxx << " ";
    }
    cerr << "\n";
  };
}
