let () = Scanf.scanf "%d %d\n" @@ fun n c ->
  let xvs = Array.init (n + 2) @@ function
    | 0 -> 0, 0
    | i when i = n + 1 -> c, 0
    | _ -> Scanf.scanf "%d %d\n" @@ fun x v -> x, v in
  let acc = Array.map snd xvs in
  for i = 1 to n + 1 do
    acc.(i) <- acc.(i) + acc.(i - 1)
  done;
  let ans_a = Array.copy acc in
  for i = 1 to n + 1 do
    ans_a.(i) <- max (acc.(i) - fst xvs.(i)) ans_a.(i - 1)
  done;
  let acc' = Array.map snd xvs in
  for i = n downto 0 do
    acc'.(i) <- acc'.(i) + acc'.(i + 1)
  done;
  let ans_b = Array.copy acc' in
  for i = n downto 0 do
    ans_b.(i) <- max (acc'.(i) - (c - fst xvs.(i))) ans_b.(i + 1)
  done;
  Printf.printf "%d\n" @@
    Array.fold_left max min_int @@
      Array.init (n + 1) @@ fun i ->
        max
          (acc.(i) - 2 * fst xvs.(i) + ans_b.(i + 1))
          (acc'.(i + 1) - 2 * (c - fst xvs.(i + 1)) + ans_a.(i))
