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

    var xi = an(0)
    def iter(min: Int, i: Int): Int = {
      if (i == an.length) {
        return min
      }
      val mini = Seq(min, Math.abs(X - xi*2)).min
      xi += an(i)
      iter(mini, i+1)
    }

    println(iter(999999999,1))
  }
}
