import java.lang.Math.abs
import java.lang.Math.min
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()

    var array = ArrayList<Long>()

    for (i in 0..n-1) {
        array.add(sc.nextInt().toLong())
    }

    var minv = solveC(array)

    println(minv)
}

fun solveC(array: ArrayList<Long>): Long {
    val n = array.size
    val sum = array.sum()
    var minv = Long.MAX_VALUE
    var x = 0L
    for (i in 0..n - 2) {
        x += array[i]
        minv = min(minv, abs(sum - 2 * x))
    }
    return minv
}