n = int(eval(input()))

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

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



ans = 0

for i in range(n):

    left = min(a[i], b[i])

    ans += left

    a[i] -= left

    b[i] -= left



    right = min(a[i+1], b[i])

    ans += right

    a[i+1] -= right

    b[i] -= right





print(ans)

import sys

stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)



i_i = lambda: int(i_s())

i_l = lambda: list(map(int, stdin.readline().split()))

i_s = lambda: stdin.readline().rstrip()



N = i_i()

A = i_l()

B = i_l()



ans = 0

for i in range(len(B)):

    if A[i] >= B[i]:

        ans += B[i]

        A[i] -= B[i]

        B[i] = 0

    else:

        ans += A[i]

        B[i] = B[i] - A[i]

        A[i] = 0

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

            ans += B[i]

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

            B[i] = 0

        else:

            ans += A[i+1]

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

            A[i+1] = 0



print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    left = min(a[i], b[i])
    ans += left
    a[i] -= left
    b[i] -= left
    right = min(a[i + 1], b[i])
    ans += right
    a[i + 1] -= right
    b[i] -= right
print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)
i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()
N = i_i()
A = i_l()
B = i_l()
ans = 0
for i in range(len(B)):
    if A[i] >= B[i]:
        ans += B[i]
        A[i] -= B[i]
        B[i] = 0
    else:
        ans += A[i]
        B[i] = B[i] - A[i]
        A[i] = 0
        if A[i + 1] >= B[i]:
            ans += B[i]
            A[i + 1] = A[i + 1] - B[i]
            B[i] = 0
        else:
            ans += A[i + 1]
            B[i] = B[i] - A[i + 1]
            A[i + 1] = 0
print(ans)

-n = int(eval(input())) -a = list(map(int, input().split())) -b = list(map(int, input().split())) +import sys + +stdin = sys.stdin +sys.setrecursionlimit(10**7) +i_i = lambda: int(i_s()) +i_l = lambda: list(map(int, stdin.readline().split())) +i_s = lambda: stdin.readline().rstrip() +N = i_i() +A = i_l() +B = i_l() -for i in range(n): -    left = min(a[i], b[i]) -    ans += left -    a[i] -= left -    b[i] -= left -    right = min(a[i + 1], b[i]) -    ans += right -    a[i + 1] -= right -    b[i] -= right +for i in range(len(B)): +    if A[i] >= B[i]: +        ans += B[i] +        A[i] -= B[i] +        B[i] = 0 +    else: +        ans += A[i] +        B[i] = B[i] - A[i] +        A[i] = 0 +        if A[i + 1] >= B[i]: +            ans += B[i] +            A[i + 1] = A[i + 1] - B[i] +            B[i] = 0 +        else: +            ans += A[i + 1] +            B[i] = B[i] - A[i + 1] +            A[i + 1] = 0