import Control.Monad

f (x:y:z:v:ws) 
 | xy == yz && yz == zv = g (v + xy) ws
 | xy == yz && zv == vw = y
 | xy == yz = v
 | yz == zv && zv == vw = x
 | yz == zv = z
 | vw == xy = z
 | vw == zv = y
 where
  xy = x - y
  yz = y - z
  zv = z - v
  vw = v - head ws
  g x (y:ys) 
   | x /= y = x
   | otherwise = g (x + xy) ys

main = do
 x <- getLine
 unless (x == "0") $ do
  l <- getLine
  print $ f (map read $ words l :: [Int])
  main