function Main(input) {
    input = input.split("\n");
    var arr = input[1].split(" ").map(Number);
    var sum = 0;
    var min = Number.MAX_SAFE_INTEGER;
    for(var i=0;i<arr.length;i++){
        sum += arr[i];
    }
    var n = 0;
    var mp = 0
    for(i=0;i<arr.length;i++){
        n += arr[i];
        var m = sum-n;
        if(min>Math.abs(n-m)){
            min = Math.abs(n-m);
        }
    }
    console.log(min);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());