
let () =
  Scanf.scanf "%d %d" @@ fun n c ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
  Array.sort compare a;

  (* (sum_v, score_f, score_fb *)
  let sa = Array.make (n+1) (0,0,0) in
  let (x0,v0) = a.(0) in
  sa.(1) <- (v0, max 0 (v0-x0), max 0 (v0-2*x0));
  for i = 2 to n do
    let (pv,py,pz), (x,v) = sa.(i-1), a.(i-1) in
    sa.(i) <- (pv+v, max py (pv+v - x), max pz (pv+v - 2*x))
  done;

  let sb = Array.make (n+1) (0,0,0) in
  let (x0,v0) = a.(n-1) in
  sb.(n-1) <- (v0, max 0 (v0 - (c-x0)), max 0 (v0 - 2*(c-x0)));
  for i = n-2 downto 0 do
    let (pv,py,pz), (x,v) = sb.(i+1), a.(i) in
    sb.(i) <- (pv+v, max py (pv+v - (c-x)), max pz (pv+v - 2*(c-x)))
  done;

  Array.init (n+1) (fun i ->
    let (_,pa,qa) = sa.(i) in
    let (_,pb,qb) = sb.(i) in
    max (pa+qb) (pb+qa))
  |> Array.fold_left max 0 |> Printf.printf "%d\n"