import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

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

solve :: Int -> [Int] -> [Int] -> Int
solve p [a] [] = min a p
solve p (a:as) (b:bs) = prevp + currp + solve nextp as bs
  where prevp = min a p
        currp = min (a - prevp) b
        nextp = b - currp

main :: IO ()
main = do
  getLine
  as <- readIntsLine
  bs <- readIntsLine
  print $ solve 0 as bs