{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed   as V

main :: IO ()
main = do
  n <- readLn
  as <- readIntsLn
  bs <- readIntsLn
  print $ solve n as bs

solve :: Int -> V.Vector Int -> V.Vector Int -> Int
solve _ as bs = snd $ V.foldl f ((V.head as), 0) $ V.zip (V.tail as) bs

f :: (Int, Int) -> (Int, Int) -> (Int, Int)
f (a1, s) (a2, b) = (a2', s')
  where a1' = max 0 (a1 - b)
        a2' = max 0 (a2 - (b - d1))
        d1 = a1 - a1'
        d2 = a2 - a2'
        s' = s + d1 + d2

readIntsLn :: IO (V.Vector Int)
readIntsLn = V.unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine
