(defn create-data [s]
  (map #(Long/parseLong %) (.split s " ")))
 
(defn sum [xs]
  (reduce + xs))
 
(defn zipWith [xs ys]
  (map vector xs ys))
 
(defn addCandy [[summ restY1 restY2] [y1 y2]]
  (if (>= restY1 restY2) 
    [(+ summ y1) (- restY1 y1) (- restY2 y2)]
    [(+ summ y2) -1 (- restY2 y2)]))
  
(defn candies [n ys1 ys2]
  (let [ys1' (drop 1 ys1) ys2' (drop-last ys2)]
    (->> (reduce addCandy [(first ys1) (sum ys1') (sum ys2')] (zipWith ys1' ys2'))
         (first)
         (+ (last ys2)))))
 
(println (candies (Long/parseLong (read-line)) (create-data (read-line)) (create-data (read-line))))
