
function Main(input) {
  var N = parseInt(input[0], 10);
  var A = input.slice(1, N + 2).map(a => parseInt(a, 10));
  var B = input.slice(N + 2).map(a => parseInt(a, 10));

  var result = 0;
  var townNum = 0;

  for(var i = 0; i < B.length; i++) {
    if (i > townNum) {
      townNum = i;
    }
    while(B[i] > 0) {
      if (B[i] > A[townNum]) {
        // 全部倒す
        B[i] -= A[townNum];
        result += A[townNum];
        townNum++;
      } else {
        // 残りが出る
        A[townNum] -= B[i];
        result += B[i];
        B[i] = 0;
      }
      if (townNum === N + 1) {
        // 途中で終わる
        return console.log(result);
      }
    }
  }
  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));