import qualified Data.ByteString.Char8 as BC
import Data.Maybe(fromJust)
import Data.List

main :: IO()
main = BC.getContents >>= print.solve.map (fst.fromJust.BC.readInt).tail.BC.lines
 
solve          :: [Int] -> Int
solve (x:y:ys) = fst $ foldl' f (y - x, min x y) ys
    where f (x,y) z = (max (z-y) x, min z y) 