let n = read_int ()
let ss, ans = Array.make (n + 1) 0, ref max_int
let _ = for i = 0 to n - 1 do ss.(i + 1) <- Scanf.scanf " %d" (+) ss.(i) done; for i = 1 to n - 1 do ans := min !ans @@ abs @@ 2 * ss.(i) - ss.(n) done; Printf.printf "%d\n" !ans