

n = int(eval(input()))

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

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



dp_town = [0]*(n+1)

dp_town[0] = min(a[0],b[0])

b[0] = b[0] - min(a[0],b[0])

for i in range(1,n):

    if b[i-1] > 0:

        dp_town[i] = min(a[i],b[i-1])

        a[i] -= b[i-1]

        b[i-1] -= min(a[i],b[i-1])

    if a[i] > 0:

        dp_town[i] += min(a[i],b[i])

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

    if i == n-1 and b[i] > 0:

        dp_town[n] += min(a[n],b[i])



print((sum(dp_town)))
def main():

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    B = [int(i) for i in input().split()]

    ans = 0

    for i in range(N):

        if A[i] < B[i]:

            B[i] -= A[i]

            ans += A[i]

            if A[i+1] < B[i]:

                ans += A[i+1]

                A[i+1] = 0

            else:

                ans += B[i]

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

        else:

            ans += B[i]

            B[i] = 0

    print(ans)





if __name__ == '__main__':

    main()

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp_town = [0] * (n + 1)
dp_town[0] = min(a[0], b[0])
b[0] = b[0] - min(a[0], b[0])
for i in range(1, n):
    if b[i - 1] > 0:
        dp_town[i] = min(a[i], b[i - 1])
        a[i] -= b[i - 1]
        b[i - 1] -= min(a[i], b[i - 1])
    if a[i] > 0:
        dp_town[i] += min(a[i], b[i])
        b[i] -= min(a[i], b[i])
    if i == n - 1 and b[i] > 0:
        dp_town[n] += min(a[n], b[i])
print((sum(dp_town)))

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] < B[i]:
            B[i] -= A[i]
            ans += A[i]
            if A[i + 1] < B[i]:
                ans += A[i + 1]
                A[i + 1] = 0
            else:
                ans += B[i]
                A[i + 1] -= B[i]
        else:
            ans += B[i]
            B[i] = 0
    print(ans)


if __name__ == "__main__":
    main()

-n = int(eval(input())) -a = list(map(int, input().split())) -b = list(map(int, input().split())) -dp_town = [0] * (n + 1) -dp_town[0] = min(a[0], b[0]) -b[0] = b[0] - min(a[0], b[0]) -for i in range(1, n): -    if b[i - 1] > 0: -        dp_town[i] = min(a[i], b[i - 1]) -        a[i] -= b[i - 1] -        b[i - 1] -= min(a[i], b[i - 1]) -    if a[i] > 0: -        dp_town[i] += min(a[i], b[i]) -        b[i] -= min(a[i], b[i]) -    if i == n - 1 and b[i] > 0: -        dp_town[n] += min(a[n], b[i]) -print((sum(dp_town))) +def main(): +    N = int(eval(input())) +    A = [int(i) for i in input().split()] +    B = [int(i) for i in input().split()] +    ans = 0 +    for i in range(N): +        if A[i] < B[i]: +            B[i] -= A[i] +            ans += A[i] +            if A[i + 1] < B[i]: +                ans += A[i + 1] +                A[i + 1] = 0 +            else: +                ans += B[i] +                A[i + 1] -= B[i] +        else: +            ans += B[i] +            B[i] = 0 +    print(ans) + + +if __name__ == "__main__": +    main()