fun main (args : Array<String>) {
	val n = readLine()
	val N : Int = n!!.toInt()
	val list = readLine()!!.split(" ").map(String::toInt)
	var wList : MutableList<Int> = mutableListOf()
	var S1 : Int = 0
	var S2 : Int = 0
	var T : Int = 0
	var calc : Int = 0
	var result : Int = 0
	for (i in 0..N - 1) {
		wList.add(list[i])
	}
	for (i in 0..N - 1) {
		T = i
		for (j in 0..T) {
			S1 += wList[j]
		}
		for (k in N - 1 downTo T + 1) {
			S2 += wList[k]
		}
			
		if (i == 0) {
			result = S2 - S1
		}
		
		calc = S2 - S1
		if (calc < 0) {
			calc = -(calc)
		}
		
		if (result >= calc) {
			result = calc
			S1 = 0
			S2 = 0
		} else {
			S1 = 0
			S2 = 0
		}
		
	}
	println("${result}")
}