import Control.Monad
import Debug.Trace
import Data.List
import Data.Ord

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 = y - x
  yz = z - y
  zv = v - z
  vw = head ws - v
  g x (y:ys) 
   | x /= y = y
   | otherwise = g (x + xy) ys

g xs = xs !! (r + 1)
 where
  ys = zipWith (-) (tail xs) xs
  z = head $ maximumBy (comparing length) $ group $ sort ys
  Just r = findIndex (/=z) ys

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