let () =
  let open Int64 in
  let len, b = Scanf.scanf "%d %Ld\n" (fun a b -> a, b) in

  let arr = Array.make len (0L,0L) in
  for i = 0 to (len-1) do
    let c = Scanf.scanf "%Ld %Ld\n" (fun a b -> a, b) in
    Array.set arr i c
  done;

  let arr_l = Array.make len (0L,0L) in
  let arr_r = Array.make len (0L,0L) in
  let arr_l2 = Array.make len (0L,0L) in
  let arr_r2 = Array.make len (0L,0L) in

  let t = ref (0L,0L) in
  for i = 0 to (len-1) do
    let distance = fst (Array.get arr i) in

    let cal = Int64.add (snd (Array.get arr i)) 
        ( if (i=0) then 0L else (snd (Array.get arr_l (i-1)))) in

    let d_sub = if (i=0) then 0L else (fst (Array.get arr_l (i-1))) in
    let d_sub = Int64.sub distance d_sub in
    let cal = Int64.sub cal d_sub in

    let tt = (distance, cal) in
    if (cal > (snd !t))
    then (
      t := tt
    )
    else ();
    Array.set arr_l i tt;
    Array.set arr_l2 i !t;
  done;

  let t = ref (0L,0L) in
  for i = 0 to (len-1) do
    let i = len-1-i in
    let distance = Int64.sub b (fst (Array.get arr i)) in
    let cal = Int64.add (snd (Array.get arr i))
        (if (i=len-1) then 0L else (snd (Array.get arr_r (i+1))) ) in

    let d_sub = if (i=len-1) then 0L else (fst (Array.get arr_r (i+1))) in
    let d_sub = Int64.sub distance d_sub in
    let cal = Int64.sub cal d_sub in

    let tt = (distance, cal) in
    if (cal > (snd !t))
    then (
      t := tt
    )
    else ();
    Array.set arr_r i tt;
    Array.set arr_r2 i !t;
  done;

  let t = ref (0L,0L) in
  for i = 0 to (len-1) do
    let j = if (i=len-1) then 0 else i+1 in

    let d_l = fst (Array.get arr_l2 i) in
    let d_r = 
      if (j = 0) then
        0L
      else
        fst (Array.get arr_r2 j) in
    let d_sub = if d_l > d_r then d_r else d_l in

    let cal_l = snd (Array.get arr_l2 i) in
    let cal_r = 
      if (j = 0) then
        0L
      else
        snd (Array.get arr_r2 j) in
    let cal = Int64.sub (Int64.add cal_l cal_r) d_sub in

    if (cal > (snd !t))
    then (
      let tt = (0L, cal) in
      t := tt
    )
    else ();
  done;

  Printf.printf "%Ld" (snd !t);

