    object Main extends App {
        var n = readInt
      	var get = readLine.split(" ")
      	var sum1 = 0
      	var sum2 = 0
      var sum3 = 100
      for(i <- 0 to n-2) {
        sum1 = sum1 + get(i).toInt
        for(j <- i+1 to n-1){
          sum2 = sum2 + get(j).toInt
        }
          sum3 = math.min(sum3,math.max(sum1,sum2)-math.min(sum1,sum2))
        sum2=0
      }
           println(sum3)
    }