import Data.IORef
import Control.Monad

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

solve :: Int -> Int -> Int -> IO Int
solve a b n = do
                a' <- newIORef a
                b' <- newIORef b
                n' <- newIORef (n - 2)
                solve' a' b' n'
    where solve' x' y' n' = do
                             n <- readIORef n'
                             if n == 0 then readIORef x'
                             else do
                              modifyIORef n' (subtract 1)
                              z <- readLn
                              x <- readIORef x'
                              y <- readIORef y'
                              when (z - y > x) $ writeIORef x' (z - y)
                              when (z < y) $ writeIORef y' z
                              solve' x' y' n'