function Main(input) {
  var WAry = input
    .trim()
    .split("\n")[1]
    .split(/\s/)
    .map(val => parseInt(val, 10));
  var minGap = Infinity;

  for (var i = 1; i < WAry.length; i++) {
    var copyAry = WAry.concat();
    var latterAry = copyAry.splice(i);

    var formerSum = 0;
    var latterSum = 0;
    for (var j = 0; j < copyAry.length; j++) {
      formerSum += copyAry[j];
    }
    for (var k = 0; k < latterAry.length; k++) {
      latterSum += latterAry[k];
    }
    minGap =
      minGap > Math.abs(formerSum - latterSum)
        ? Math.abs(formerSum - latterSum)
        : minGap;
  }
  console.log(minGap);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
