import std.stdio, std.algorithm, std.array, std.conv, std.string;

void main()
{
  long n, c;
  readf("%d %d\n", &n, &c);
  long[] xs = new long[](n + 1);  
  long[] rs = new long[](n + 1);
  long[] vs = new long[](n);  
  foreach (i; 0..n) {
    readf("%d %d\n", &(xs[i + 1]), &(vs[i]) );
    rs[n - i] = c - xs[i + 1];
  }
  xs[0] = 0;
  rs[0] = 0;

  // 逆に回ったときのカロリー
  long[] rpts = new long[](n + 1);
  rpts[0] = 0;
  foreach (i; 0..n) {
    rpts[i + 1] = rpts[i] - (rs[i + 1] - rs[i]) + vs[n - i - 1];
  }

  long[] pts = new long[](n + 1);
  pts[0] = 0;
  foreach (i; 0..n) {
    pts[i+1] = pts[i] - (xs[i + 1] - xs[i]) + vs[i];
  }

  long[] allpts = rpts ~ pts;
  foreach (i; 0..n) {
    auto p = pts[i] - xs[i] + rpts[0..(n-i)].dup.sort()[$-1];
    auto p2 = rpts[i] - rs[i] + pts[0..(n-i)].dup.sort()[$-1];
    allpts ~= p;
    allpts ~= p2;
  }

  writeln(allpts.sort()[$-1]);

}
