object Main extends App {
  
  def run(): Unit = {
    import io.StdIn._
    val N = readLine().toInt
    val nums = readLine().split("\\s").map(_.toInt).iterator
    
    val M = 1e+18.toLong
    var ans = 0L
    while (nums.hasNext) {
      ans += nums.next
      if (M < ans) {
        println(-1)
        return ()
      }
    }
    println(ans)
  }
  
  run()
}