import math._
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val as = (1 to n) map(_ => sc.nextLong())
  
  val ans = (0 to n).map(i => abs(as.take(i).sum - as.drop(i).sum)).min
  println(ans)
}