main = do
  getLine
  li <- getLine
  let as = map read $ words li
  li <- getLine
  let bs = map read $ words li
  let ans = compute as bs
  print ans

compute :: [Int] -> [Int] -> Int
compute as bs = fst $ foldl step (0,0) $ zip as $ bs++[0]

step (total,carry) (a,b) = (t1,b1)
  where
    a1 = max 0 (a - carry)
    a2 = max 0 (a1 - b)
    t1 = total + a - a2
    b1 = b - (a1 - a2)
