var print= function(elem){
    console.log(elem);
};

var toInt = function(elem) {
    return parseInt(elem, 10);
};
var toIntArr = function(line) {
    var intArray = line.split(' ').map(toInt);
    if(intArray.length === 1) {
        return intArray[0];
    } else {
        return intArray;
    }
};
var inputs = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

//end of template

var N = toInt(inputs[0]);
var a= toIntArr(inputs[1]);


var sum_array=Array([0]);
var _sum = 0;
for(var i=0;i<N;i++){
    _sum +=a[i];
    sum_array.push(_sum)
}

max_sum = sum_array[sum_array.length-1];
var diff =9999999999999

for(var i=1;i<N;i++){
    diff = Math.min( diff, Math.abs(max_sum - 2*sum_array[i])   )
}


print(diff);