import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad.State (State, evalState, gets, modify)
import Data.Hashable (Hashable)
import Data.HashMap.Strict (HashMap, lookup, insert, empty)
import Data.Maybe (maybe)
import Data.Array as A

main :: IO ()
main = breads >>= main'
    where
        main' [n, z, w] = breads >>= print . solve n w

solve :: Int -> Int -> [Int] -> Int 
solve n w xs = run calc (True, 0, w)
    where
        arr = A.listArray (0, n - 1) xs
        calc f (b, idx, w)
            | idx < n - 1 = cmpf b <$> f (b, idx + 1, w) <*> f (not b, idx + 1, arr A.! idx)
            | otherwise = return . abs $ w - arr A.! idx 

        cmpf b 
            | b = max
            | otherwise = min

type Memoizer a b = a -> State (HashMap a b) b

run :: (Hashable a, Eq a) => (Memoizer a b -> Memoizer a b) -> a -> b
run f = flip evalState empty . memoizeFix f

memoizeFix :: (Hashable a, Eq a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.HashMap.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.HashMap.Strict.insert x))) return

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

