let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let x = Array.copy a in
  for i = 1 to n - 1 do x.(i) <- x.(i) + x.(i-1) done;
  let z = Array.fold_left (+) 0 a in
  let ans = ref max_int in
  for i = 0 to n - 2 do
    let t = abs (z - 2 * x.(i)) in
    if t < !ans then ans := t;
  done;
  Printf.printf "%d\n" !ans