
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord

--import qualified Data.IntSet as S
import qualified Data.Sequence as S

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- r' :: IO [Int]
    bs <- r' :: IO [Int]
    print $ solve as bs 0

solve :: [Int] -> [Int] -> Int -> Int
solve _ [] ac = ac
solve (a:a':as) (b:bs) ac = if a < b then
    let monstInNext = max 0 (a'-(b-a))
        defInNext = a' - monstInNext
    in solve (monstInNext:as) bs (ac+a+defInNext)
    else solve (a':as) bs (ac+b)
