import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents

main = do
    argMatrix <- getIntMatrix
    print $ solve argMatrix


solve :: [[Integer]] -> Integer
solve ll =  2 * target - rate
    where 
        rate = head $ head ll
        target = head $ last ll 
