solve (a1:a2:as) (b:bs)
  = let a2' = max 0 (a2 - max 0 (b - a1)) in 
    min (a1+a2) b + solve (a2':as) bs
solve _ _ = 0

main = do
  getLine
  a <- map read.words<$>getLine
  b <- map read.words<$>getLine
  print $ solve a b