import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

f = g 0

g r (a:a':as) (b:bs) = g (r+t1+t2) ((a'-t2):as) bs
  where
    t1 = min a b
    rb = b - t1
    t2 = min a' rb
    
g r _ _ = r

getInts = map read . words <$> getLine :: IO [Int]

main = getLine >> f <$> getInts <*> getInts >>= print