    // inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
 
	var line1 = input[0].split(" ");
	var num = Number(line1[0])
	var data = input[1].split(" ");
	for(var i = 0; i<num; i++){
	    data[i] = Number(data[i]);
	}
	
	var sum = 0;

	for(var i = 0; i<num; i++){
	    sum += data[i];
    }

    var leftSum = 0
    var diff = 1e30;
    var ans = 1e30;

	for(var ite=0; ite<num-1;ite++){
	    leftSum += data[ite];
	    diff = Math.abs((sum-leftSum) - leftSum);
//	    console.log("i:"+ite+" ls:"+leftSum+" sum:"+sum+" diff:"+diff);
	    if(diff<ans){
	        ans = diff;
	    }
	}	
    
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));