import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B

f :: [Int] -> [Int] -> Int
f _ [] = 0
f (x:y:as) (b:bs) = if x <= b then x + (if (max 0 $ y - (b - x)) == 0 then y else b-x) + (f ((max 0 $ y - (b - x)):as) bs)
  else b + (f (y:as) bs)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  bs <- map read.words <$> getLine :: IO [Int]

  print $ f as bs
