object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val a = readLine().split(" ").toList.map(_.toInt)
    val total = a.sum
    def searchMin(intList: List[Int], min: Int = (a.head - a.drop(1).sum).abs): Int = {
      intList match {
        case int :: tail if tail == Nil => min
        case int :: tail =>
          val diff = (int - tail.sum).abs
          searchMin(tail, if (diff < min) diff else min)
      }
    }
    println(searchMin(a))
  }
}
