import qualified Data.ByteString.Char8 as B
import Data.Maybe

solve [_] [] = 0
solve (a:b:as) (x:xs)
    | a >= x = x + solve (b:as) xs
    | otherwise = (a + rest') + solve (b':as) xs
    where
        rest = x - a
        rest' = min b rest
        b' = max 0 (b - rest')


main = do
    n <- readLn :: IO Int
    as <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    bs <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    print $ solve as bs