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 else a1 - (c - a2) b' | d == 0 = 0 | otherwise = if (b1 + c - a2) > d then d else b1 + c - a2 main = do [as, bs, cd] <- map (map rInt . words) <$> replicateM 3 getLine print $ solve as bs cd