function Main(input) {
    var result;
    const N = parseInt(input.shift());
    var Ws = input.map(v => parseInt(v));
    var sum = 0;
    Ws.forEach(element => {
        sum += element;
    });

    var smallSum = 0;
    var div = Number.MAX_SAFE_INTEGER;
    for (var i = 0; i < Ws.length; i++) {
        div = Math.min(div, Math.abs(sum - smallSum * 2));
        smallSum += Ws[i];
    }
    div = Math.min(div, Math.abs(sum - smallSum * 2));
    console.log(div);
    
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));