let _ = readLine()
let W = readLine()!.characters.split(" ").map{Int(String($0))!}
var S1 = 0
var S2 = W.reduce(0){$0+$1}
var ans = S2
for i in W {
    S1 += i
    S2 -= i
    ans = min(abs(S1-S2), ans)
}
print(ans)