main=do
 getLine;a<-map read.words<$>getLine;b<-map read.words<$>getLine
 print(f b a)
  where f [] _ = 0
        f (x:a) (y:z:b) = if y>=x then x+(f a (z:b)) else (min (z+y) x)+(f a ((max 0 (z+y-x)):b))