import Control.Applicative
import Control.Monad

solve :: Int -> Int -> Int -> IO Int
solve x y n
    | n == 0    = return y
    | otherwise = do
        z <- readLn
        solve (min x z) (max y (z - min x z)) (n - 1)

main :: IO ()
main = do
    n <- readLn
    x <- readLn
    y <- readLn
    solve x y (n - 2) >>= print