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

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