'use strict'

function main(input) {
  input = input.split('\n').map(v => v.split(' ').map(v => ~~v))
  const n = input[0][0]

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

  let tmpmin = Number.MAX_SAFE_INTEGER
  for (let i = 0; i < n - 1; i++) {
    let x = sums[i]
    let y = sums[n - 1] - sums[i]

    let diff = x >= y ? x - y : y - x
    // console.log(diff, x,y, sums)
    if (tmpmin > diff) {
      tmpmin = diff
    }
  }
  const ans = tmpmin

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