function Main(input) {
  input = input.split("\n");
  var n = input[0];
  tmp = input[1].split(" ");
  a = new Array(n).fill(0);
  var m =0;
  b = new Array(n).fill(0);
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
    m+=a[i];
    if(i!=0){
    b[i]=b[i-1]+a[i];
    }else{
      b[i]=a[i];
    }
  }
  var ans=100000000000;
  for(i=0;i<n-1;i++){
    ans=Math.min(ans,Math.abs((m-b[i])-b[i]));
  }

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));