import Data.List

step :: (Integer, Integer) -> (Integer, Integer) -> (Integer, Integer)
step (a, b) (k, c) = (k + min a (b+c), max 0 (min b (b+c-a)))

main = do
  n <- readLn :: IO Int
  aa <- map read . words <$> getLine :: IO [Integer]
  bb <- map read . words <$> getLine :: IO [Integer]
  putStrLn . show $ fst $ foldr step (0, 0) $ zip aa (0:bb)
