from sys import stdin,stdout



if __name__=="__main__":

    n=int(stdin.readline())



    a=[int(x) for x in stdin.readline().split()]

    b=[int(x) for x in stdin.readline().split()]



    cnt=0



    for i in range(n):

        if(a[i]>=b[i]):

            cnt+=b[i]

        else:

            cnt+=a[i]

            d=b[i]-a[i]

            cnt+=min(a[i+1],d)

            if(d>a[i+1]):

                a[i+1]=0

            else: a[i+1]-=d

            

    stdout.write(str(cnt)+"\n")

n = int(eval(input()))

A = list(map(int, input().split()))

B = list(map(int, input().split()))

a1 = sum(A)

for i in range(n):

  b = B[i]

  if A[i] >= b:A[i] -= b

  else:

    if A[i+1]+A[i] >= b:

      A[i+1] = A[i+1]+A[i]-b

      A[i] = 0

    else:A[i], A[i+1] = 0, 0

a2 = sum(A)

print((a1-a2))
from sys import stdin, stdout

if __name__ == "__main__":
    n = int(stdin.readline())
    a = [int(x) for x in stdin.readline().split()]
    b = [int(x) for x in stdin.readline().split()]
    cnt = 0
    for i in range(n):
        if a[i] >= b[i]:
            cnt += b[i]
        else:
            cnt += a[i]
            d = b[i] - a[i]
            cnt += min(a[i + 1], d)
            if d > a[i + 1]:
                a[i + 1] = 0
            else:
                a[i + 1] -= d
    stdout.write(str(cnt) + "\n")

n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a1 = sum(A)
for i in range(n):
    b = B[i]
    if A[i] >= b:
        A[i] -= b
    else:
        if A[i + 1] + A[i] >= b:
            A[i + 1] = A[i + 1] + A[i] - b
            A[i] = 0
        else:
            A[i], A[i + 1] = 0, 0
a2 = sum(A)
print((a1 - a2))

-from sys import stdin, stdout - -if __name__ == "__main__": -    n = int(stdin.readline()) -    a = [int(x) for x in stdin.readline().split()] -    b = [int(x) for x in stdin.readline().split()] -    cnt = 0 -    for i in range(n): -        if a[i] >= b[i]: -            cnt += b[i] +n = int(eval(input())) +A = list(map(int, input().split())) +B = list(map(int, input().split())) +a1 = sum(A) +for i in range(n): +    b = B[i] +    if A[i] >= b: +        A[i] -= b +    else: +        if A[i + 1] + A[i] >= b: +            A[i + 1] = A[i + 1] + A[i] - b +            A[i] = 0 -            cnt += a[i] -            d = b[i] - a[i] -            cnt += min(a[i + 1], d) -            if d > a[i + 1]: -                a[i + 1] = 0 -            else: -                a[i + 1] -= d -    stdout.write(str(cnt) + "\n") +            A[i], A[i + 1] = 0, 0 +a2 = sum(A) +print((a1 - a2))