-- C - City Savers

main = do
  n_str <- getLine
  let n = read n_str :: Int
  town_str <- getLine
  let town = take (n + 1) (map read (words town_str) :: [Int])
  savers_str <- getLine
  let savers = take n (map read (words savers_str) :: [Int])
  let ans = solve town savers 0 0
  putStrLn(show ans)

solve :: [Int] -> [Int] -> Int -> Int -> Int
solve (t0:ts) (s0:ss) sc count =
  if rest_t < s0
  then
    solve ts ss (s0 - rest_t) (t0 + count)
  else
    solve ts ss 0 (s0 + sc + count)
  where
    rest_t = t0 - sc

solve (t0:_) [] sc count =
  if t0 < sc
  then
    count + t0
  else
    count + sc
  

