module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Control.Monad.ST (runST)
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.Vector.Unboxed as V
import Data.STRef.Strict



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> [Int] -> Int
solve n as bs = runST $ do
    av <- V.thaw $  V.fromList as
    bv <- V.thaw $  V.fromList bs
    ans <- newSTRef 0
    forM_ [0..n-1] $ \i -> 
        do
            b <- MV.read bv i
            a <- MV.read av i 
            a' <- MV.read av (i  + 1)
            let kill = min a b
            let remainB = b - kill
            modifySTRef ans (+kill)
            MV.write av i (a - kill)
            let kill' = min a' remainB
            modifySTRef ans (+kill')
            MV.write av (i + 1) (a' - kill')
    readSTRef ans


main = do
    n <- readInt
    as <- readInts
    bs <- readInts
    print $ solve n as bs
