import Control.Applicative
import Data.List

solve acc _ [] = acc
solve acc (a0:a1:as) (b:bs) = do
  let (r, b') = if a0 <= b then (a0, b - a0) else (b, 0)
  let (l, a1') = if a1 <= b' then (a1, 0) else (b', a1 - b')
  let acc' = acc + r + l
  solve acc' (a1':as) bs


main = do
  n <- read <$> getLine :: IO Int
  --[n, m] <- (map read).words <$> getLine :: IO [Int]
  as <- (map read).words <$> getLine :: IO [Int]
  bs <- (map read).words <$> getLine :: IO [Int]
  print $ solve 0 as bs
