object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val an = List.fill(n)(sc.nextInt)
    val X = an.sum

    def iter(min: Int, i: Int): Int = {
      if (i == an.length) {
        return min
      }
      val xi = an.splitAt(i)._1.sum
      val diff = Math.abs(X - xi*2)
      val mini = if (min > diff) {
        diff
      } else {
        min
      }
      iter(mini, i+1)
    }

    println(iter(999999999,1))
  }
}
