object Main{
  def check(l: List[Int], limit: Int, count: Int = 1, ans:Int = Int.MaxValue): Int = {
    // 手前count分取って，残りをくまに渡す
    if(limit == count)
      ans
    else
      check(l, limit, count + 1, Math.min(ans, Math.abs(l.take(count).sum - l.drop(count).sum)))
  }

  def main(args:Array[String]) = {
    val list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList;
    val l = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList;

    var my: Int = 0
    var kuma: Int = 0
    println(check(l, list(0)))
  }
}