solve :: [Int] -> [Int] -> (Int,Int)

solve [] [] = (0,0)

solve [] (y:ys) = (0,y)

solve (x:xs) [] = (0,0)

solve (x:xs) (y:ys) = 
    let (x1,y1) = solve xs ys
        y2 = y + y1
    in if x < y2
        then (x+x1,if y < (y2-x) then y else (y2-x))
        else (y2+x1,0)

main :: IO ()
main = do 
    
    line <- getLine

    input1 <- map read . words <$> getLine

    input2 <- map read . words <$> getLine    

    let (result,_) = solve input1 (0:input2)
    
    putStrLn ( show result )
