'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

  const n = input[0]
  const cards = input[1]
  const sums = [0]
  // 累積和
  for (let i = 0; i < n; i++) {
    sums.push(sums[i] + cards[i])
  }

  let min = Number.MAX_SAFE_INTEGER
  const total = sums[n]
  for (let i = 1; i < n; i++) {
    let tmp = Math.abs(total - sums[i] - sums[i])
    min = Math.min(min, tmp)
  }

  console.log(min)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
