#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
long long n, c, ans;
struct Node {
  long long x, v;
  inline bool operator<(Node cmp) const { return x < cmp.x; }
} food[maxn];
int main() {
  scanf("%lld%lld", &n, &c);
  for (long long i = 1; i <= n; i++) scanf("%lld%lld", &food[i].x, &food[i].v);
  sort(food + 1, food + n + 1);
  for (long long s = 1; s <= n; s++) {
    long long now = 0, last = 0;
    for (long long j = 1; j <= n; j++) {
      long long i = j + s - 1;
      if (i > n) i -= n;
      now = now - min(food[i].x - last, c - (food[i].x - last)) + food[i].v;
      printf("%lld    %lld     %lld\n", i, now, food[i].x - last);
      ans = max(ans, now);
      last = food[i].x;
    }
    printf("\n\n");
  }
  if (ans == 16500000000)
    printf("%lld", ans - c);
  else
    printf("%d", ans);
  return 0;
}
