type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f

let util = ABC(stdin)

let N = util.Scan1 int
let xs = util.ScanVecH int

let tot = Array.sum xs

//よくわかんないから全部やる
[ for i in 0..N-1 ->
    let s = xs |> Array.take i |> Array.append [|0|] |> Array.sum
    abs (tot - 2 * s)
]
|> List.min
|> printfn "%d"
