import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Control.Monad.ST
import Data.Array.ST
import Data.Function
import qualified Data.Vector.Unboxed as VU

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- VU.fromList <$> getIntList
    print $ solve n as

solve n as = runST $ do
    arr <- newArray ((0,0),(n-1,n-1)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ [n-1,n-2..0] $ \i -> do
        forM_ [i..n-1] $ \j -> do
            if i == j then
                writeArray arr (i,j) (as VU.! i)
            else do
                x <- readArray arr (i+1,j)
                y <- readArray arr (i,j-1)
                writeArray arr (i,j) $ max (as VU.! i - x) (as VU.! j - y)
    readArray arr (0,n-1)