N = int( eval(input()) )

A, B = list( [int(x) for x in input().split(" ")] ), list( [int(x) for x in input().split(" ")] )

#A = monsters. B = number of to be able to kill monsters.殺せる数



 

def kill_monsters(Ai, Bi):



    Ai -= Bi

    Bi = 0



    if Ai < 0:

        Bi += -1*Ai

        Ai = 0



    return (Ai, Bi)

 

def main(local_A, local_B, lim):

 

    for i in range(lim):

        local_A[i], local_B[i] = kill_monsters(local_A[i], local_B[i])

 

        if 0 < local_B[i]:

            local_A[i+1], local_B[i] = kill_monsters(local_A[i+1], local_B[i])

 

    return [local_A, local_B]



print(( sum(A) - sum(main(A, B, N)[0]) ))
def read():

    N = int(eval(input()))

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

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



    return (N, A, B)



def kill(A, B):

    if B < A:

        A = A - B

        B = 0

    else:

        B = B - A

        A = 0

    

    return (A, B)



def main(N, A, B):



    for i in range(N):

        A[i], B[i] = kill(A[i], B[i])

        if 0 < B[i]:

            A[i+1], B[i] = kill(A[i+1], B[i])

    

    return (A, B)



N, A, B = read()

print((sum(A) - sum(main(N, A, B)[0])))
N = int(eval(input()))
A, B = list([int(x) for x in input().split(" ")]), list(
    [int(x) for x in input().split(" ")]
)
# A = monsters. B = number of to be able to kill monsters.殺せる数
def kill_monsters(Ai, Bi):
    Ai -= Bi
    Bi = 0
    if Ai < 0:
        Bi += -1 * Ai
        Ai = 0
    return (Ai, Bi)


def main(local_A, local_B, lim):
    for i in range(lim):
        local_A[i], local_B[i] = kill_monsters(local_A[i], local_B[i])
        if 0 < local_B[i]:
            local_A[i + 1], local_B[i] = kill_monsters(local_A[i + 1], local_B[i])
    return [local_A, local_B]


print((sum(A) - sum(main(A, B, N)[0])))

def read():
    N = int(eval(input()))
    A = list(map(int, input().split(" ")))
    B = list(map(int, input().split(" ")))
    return (N, A, B)


def kill(A, B):
    if B < A:
        A = A - B
        B = 0
    else:
        B = B - A
        A = 0
    return (A, B)


def main(N, A, B):
    for i in range(N):
        A[i], B[i] = kill(A[i], B[i])
        if 0 < B[i]:
            A[i + 1], B[i] = kill(A[i + 1], B[i])
    return (A, B)


N, A, B = read()
print((sum(A) - sum(main(N, A, B)[0])))

-N = int(eval(input())) -A, B = list([int(x) for x in input().split(" ")]), list( -    [int(x) for x in input().split(" ")] -) -# A = monsters. B = number of to be able to kill monsters.殺せる数 -def kill_monsters(Ai, Bi): -    Ai -= Bi -    Bi = 0 -    if Ai < 0: -        Bi += -1 * Ai -        Ai = 0 -    return (Ai, Bi) +def read(): +    N = int(eval(input())) +    A = list(map(int, input().split(" "))) +    B = list(map(int, input().split(" "))) +    return (N, A, B) -def main(local_A, local_B, lim): -    for i in range(lim): -        local_A[i], local_B[i] = kill_monsters(local_A[i], local_B[i]) -        if 0 < local_B[i]: -            local_A[i + 1], local_B[i] = kill_monsters(local_A[i + 1], local_B[i]) -    return [local_A, local_B] +def kill(A, B): +    if B < A: +        A = A - B +        B = 0 +    else: +        B = B - A +        A = 0 +    return (A, B) -print((sum(A) - sum(main(A, B, N)[0]))) +def main(N, A, B): +    for i in range(N): +        A[i], B[i] = kill(A[i], B[i]) +        if 0 < B[i]: +            A[i + 1], B[i] = kill(A[i + 1], B[i]) +    return (A, B) + + +N, A, B = read() +print((sum(A) - sum(main(N, A, B)[0])))