'use strict'

function main(input) {

  const nums = input.split('\n')[1].split(' ').map(n => Number(n));
  const arr = [0];

  for (let i = 0, sum = 0; i < nums.length; i++) {
    sum += nums[i];
    arr.push(sum);
  }

  let min = arr[arr.length - 1];
  for (let i = 1; i < arr.length - 1; i++) {
    const abs = Math.abs(arr[i] - (arr[arr.length - 1] - arr[i]));
    min = Math.min(min, abs);
  }

  console.log(min);
}

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