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

main :: IO ()
main = do
  (_,as,bs) <- readParams
  print $ solve as bs

readParams :: IO (Int,[Int],[Int])
readParams = do
  n <- readLn
  as <- readInts
  bs <- readInts
  return (n,as,bs)

readInts :: IO [Int]
readInts = map b2int . B.words <$> B.getLine
  where b2int = fst . fromJust . B.readInt

solve :: [Int] -> [Int] -> Int
solve = solve' 0

solve' :: Int -> [Int] -> [Int] -> Int
solve' n _ [] = n
solve' n (x:y:ys) (z:zs)
  | x < z     = solve' (n+x+rest) (y-rest:ys) zs
  | otherwise = solve' (n+z) (y:ys) zs
  where rest = min y (z-x)
