import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  _ <- BS.getLine
  a <- readInts
  b <- readInts
  print $ solve a b

solve [a] [] = 0
solve (a:a':xa) (b:xb) = min a b + min (b - min a b) a' + solve (a' - min a' (b - min a b) : xa) xb
