while true
    n = gets.to_i
    break if n == 0
    arr = gets.chomp.split.map(&:to_i)
    diff = []
    arr[0...-1].each_with_index{|x, i| diff << arr[i + 1] - x}
    i = diff.index(0)
    if i
        puts arr[i]
        next
    end
    h = Hash.new(0)
    diff.each{|d| h[d] += 1}

    if h.length == 2 && h.values.min == 1
        puts (diff[0] == diff[1]) ? arr[-1] : arr[0]
    else
        hen = diff.find_all{|x| h[x] == 1}
        k = h.keys
        hen << (k[0] * 2 == k[1] ? k[0] : k[1]) if hen.empty?
        i = diff.index{|x| hen.include? x}
        puts arr[i + 1]
    end
end
