import Control.Monad rInt :: String -> Int rInt = read solve (a1:a2:[]) (b1:b2:[]) (c:d:[]) = a' + b' where a' | c == 0 = a1 | otherwise = if (c - a2) >= 0 then a1 - (c - a2) else a1 b' | d == 0 = 0 | otherwise = if (b1 + a1 - a') >= d then d else b1 + a1 - a' main = do [as, bs, cd] <- map (map rInt . words) <$> replicateM 3 getLine print $ solve as bs cd