
hoge :: Int -> [Int] -> [Int] -> Int
hoge pre [x] [] = min pre x
hoge pre (x:xs) (y:ys) =
  let
    heroes = pre + y
    mons = min heroes x
    next = max 0 $ heroes - x
  in mons + hoge next xs ys

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

main = do
  _ <- getLine
  xs <- getInts
  ys <- getInts
  print $ hoge 0 xs ys


