import scala.io.StdIn.{readInt,readLine}

object Main {
  def scan(h:Array[Long],i:Int):Long = {
    if(i==3 && (h(3)-h(0)) != (h(1)-h(0))*3) {
      if(h(1)-h(0) == h(2)-h(1)) h(3)
      else if(h(3)-h(1) == h(1)-h(0)) h(2)
      else if(h(2)-h(0) == h(3)-h(2)) h(1)
      else if(h(3)-h(2) == h(2)-h(1)) h(0)
      else 999
    } else {
      if(h(i)-h(i-1) != h(i-1)-h(i-2)) h(i) else scan(h,i+1)
    }
  }

  def main(args:Array[String]):Unit = {
    println {
      Iterator.continually(readInt).takeWhile(_!=0).map { n=>
        val h = readLine.split(" ").map(_.toLong)
        scan(h,3)
      }.mkString("\n")
    }
  }
}