#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) {
    return 1;
  } else {
    return 0;
  }
}
template <typename T>
T gcd(T a, T b) {
  if (b > 0) {
    return gcd(b, a % b);
  } else {
    return a;
  }
}
template <typename T>
T lcm(T a, T b) {
  T g = gcd(a, b);
  return a * b / g;
}
void clear(std::queue<pair<int, int> > &q) {
  std::queue<pair<int, int> > empty;
  std::swap(q, empty);
}
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
template <typename T>
std::vector<T> enum_div(T n) {
  std::vector<T> ret;
  for (T i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}
map<int, int> prime_factor(int n) {
  map<int, int> ret;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
class DisjointSet {
 public:
  vector<int> rank, p;
  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) {
      makeSet(i);
    }
  }
  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  bool same(int x, int y) { return findSet(x) == findSet(y); }
  void unite(int x, int y) { link(findSet(x), findSet(y)); }
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }
  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};
int main() {
  int N;
  ll C;
  cin >> N >> C;
  ll x[N];
  ll v[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }
  ll hmax[N];
  ll rmax[N];
  ll tmp = 0;
  if (N == 1) {
    ll t = max(v[0] - x[0], v[0] - C + x[0]);
    if (t > 0) {
      cout << t << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      tmp += v[i] - x[i];
      if (tmp > 0) {
        hmax[i] = tmp;
      } else {
        hmax[i] = 0;
      }
    } else {
      tmp += v[i] - x[i] + x[i - 1];
      if (tmp > hmax[i - 1]) {
        hmax[i] = tmp;
      } else {
        hmax[i] = hmax[i - 1];
      }
    }
  }
  tmp = 0;
  for (int i = 0; i < N; i++) {
    int id = N - i - 1;
    if (i == 0) {
      tmp += v[id] - (C - x[id]);
      if (tmp > 0) {
        rmax[i] = tmp;
      } else {
        rmax[i] = 0;
      }
    } else {
      tmp += v[id] - abs(x[id] - x[id - 1]);
      if (tmp > rmax[i - 1]) {
        rmax[i] = tmp;
      } else {
        rmax[i] = rmax[i - 1];
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll tmp = 0;
    if (i == N - 1) {
      tmp = hmax[i];
    } else {
      tmp = hmax[i] + rmax[N - i - 2] - x[i];
    }
    ans = max(tmp, ans);
  }
  for (int i = 0; i < N; i++) {
    ll tmp = 0;
    if (i == N - 1) {
      tmp = rmax[i];
    } else {
      tmp = rmax[i] + hmax[N - i - 2] - C + x[N - i - 1];
    }
    ans = max(tmp, ans);
  }
  cout << ans << endl;
}
