kr :: [Int] -> [Int] -> Int
kr _ [] = 0
kr (y:y':ys) (x:xs) = min y x + min y' (x - min y x) + kr ((y' - min y' (x - min y x)):ys) xs

main = do
    _ <- getLine
    a <- map read . words <$> getLine :: IO [Int]
    b <- map read . words <$> getLine :: IO [Int]
    print $ kr a b
