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 min = 999999999;
    (1 until n).foreach{ i =>
      val splitedCards = an.splitAt(i)
      val diff = Math.abs(X - splitedCards._1.sum*2)
      if (min > diff) {
        min = diff
      }
    }

    println(min)
  }
}
