import scala.io.StdIn.readLine

object Main extends App {
  val MOD = 1000000007
  val n = readLine.toInt
  val a = readLine.split(" ").map(_.toLong)

  val s = a.sum
  var cur = 0.toLong
  val t = for(i <- 0 until n - 1) yield {
    cur += a(i)
    cur
  }

  val ans = t.map(x => math.abs(x * 2 - s)).min

  println(ans)
}