'use strict'

const main = input => {
	const w = input.trim().split('\n')[1].split(' ').map(Number)
	const total = w.reduce((acc, cur) => acc + cur, 0)
	let min = total

	for (let i = 0; i < (w.length - 1); i++) {
		const s1 = w.slice(0, i + 1).reduce((acc, cur) => acc + cur, 0)
		const s2 = w.slice(i + 1).reduce((acc, cur) => acc + cur, 0)
		min = Math.min(min, Math.abs((s1) - (total - s1)))
	}

	console.log(min)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
