let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let abs = Array.init n (fun _ -> Scanf.scanf "%d %d\n" (fun a b -> a, b)) in
  if List.for_all (fun (a, b) -> a = b) (Array.to_list abs) then print_endline "0"
  else 
    Array.fold_left (fun (x, y) (a, b) ->
      if b < a then (x, y + a - b)
      else (x + a, y + b - a)) (0, 0) abs
    |> (fun (x, y) -> x + y / 2)
    |> Printf.printf "%d\n" 