from collections import defaultdict





if __name__=="__main__":

    brave_n = int(eval(input()))

    monster_dic = defaultdict(int)

    brave_dic = defaultdict(int)

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

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

    kill_count = 0



    for i, m in enumerate(monster_n):

        monster_dic[i] = m



    for i, b in enumerate(brave_can):

        brave_dic[i] = b



    for i in range(len(brave_dic)):



        if brave_dic[i] >= monster_dic[i]:

            kill = monster_dic[i]

            monster_dic[i] -= kill

            brave_dic[i] -= kill

            kill_count += kill

            if brave_dic[i] >= monster_dic[i+1]:

                kill = monster_dic[i+1]

                monster_dic[i+1] -= kill

                brave_dic[i] -= kill

                kill_count += kill

            else:

                kill = brave_dic[i]

                monster_dic[i+1] -= kill

                brave_dic[i] -= kill

                kill_count += kill

        else :

            kill = brave_dic[i]

            monster_dic[i] -= kill

            brave_dic[i] -= kill

            kill_count += kill



    print(kill_count)

N = int(eval(input()))

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

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

d_sum = sum(A)



for i in range(N):

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

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

    else:

        B[i] -= A[i]

        A[i] = 0

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

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

            B[i] = 0

        else:

            A[i+1] = 0



print((d_sum - sum(A)))
from collections import defaultdict

if __name__ == "__main__":
    brave_n = int(eval(input()))
    monster_dic = defaultdict(int)
    brave_dic = defaultdict(int)
    monster_n = list(map(int, input().split()))
    brave_can = list(map(int, input().split()))
    kill_count = 0
    for i, m in enumerate(monster_n):
        monster_dic[i] = m
    for i, b in enumerate(brave_can):
        brave_dic[i] = b
    for i in range(len(brave_dic)):
        if brave_dic[i] >= monster_dic[i]:
            kill = monster_dic[i]
            monster_dic[i] -= kill
            brave_dic[i] -= kill
            kill_count += kill
            if brave_dic[i] >= monster_dic[i + 1]:
                kill = monster_dic[i + 1]
                monster_dic[i + 1] -= kill
                brave_dic[i] -= kill
                kill_count += kill
            else:
                kill = brave_dic[i]
                monster_dic[i + 1] -= kill
                brave_dic[i] -= kill
                kill_count += kill
        else:
            kill = brave_dic[i]
            monster_dic[i] -= kill
            brave_dic[i] -= kill
            kill_count += kill
    print(kill_count)

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

-from collections import defaultdict - -if __name__ == "__main__": -    brave_n = int(eval(input())) -    monster_dic = defaultdict(int) -    brave_dic = defaultdict(int) -    monster_n = list(map(int, input().split())) -    brave_can = list(map(int, input().split())) -    kill_count = 0 -    for i, m in enumerate(monster_n): -        monster_dic[i] = m -    for i, b in enumerate(brave_can): -        brave_dic[i] = b -    for i in range(len(brave_dic)): -        if brave_dic[i] >= monster_dic[i]: -            kill = monster_dic[i] -            monster_dic[i] -= kill -            brave_dic[i] -= kill -            kill_count += kill -            if brave_dic[i] >= monster_dic[i + 1]: -                kill = monster_dic[i + 1] -                monster_dic[i + 1] -= kill -                brave_dic[i] -= kill -                kill_count += kill -            else: -                kill = brave_dic[i] -                monster_dic[i + 1] -= kill -                brave_dic[i] -= kill -                kill_count += kill +N = int(eval(input())) +A = list(map(int, input().split())) +B = list(map(int, input().split())) +d_sum = sum(A) +for i in range(N): +    if A[i] >= B[i]: +        A[i] = A[i] - B[i] +    else: +        B[i] -= A[i] +        A[i] = 0 +        if A[i + 1] >= B[i]: +            A[i + 1] -= B[i] +            B[i] = 0 -            kill = brave_dic[i] -            monster_dic[i] -= kill -            brave_dic[i] -= kill -            kill_count += kill -    print(kill_count) +            A[i + 1] = 0 +print((d_sum - sum(A)))