def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby

    #from itertools import product

    from bisect import bisect_left,bisect_right

    import heapq

    from math import floor, ceil

    #from operator import itemgetter



    #inf = 10**17

    #mod = 10**9 + 7



    N = int(eval(input()))

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

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

    res = 0

    n = 0

    for i in range(N):

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

        c = max(a[i]-n, 0)

        n = max(b[i]-c, 0)

    res += min(n, a[-1])

    print(res)



if __name__ == '__main__':

    main()
def main():

    import sys

    input = sys.stdin.readline

    sys.setrecursionlimit(10**7)

    from collections import Counter, deque

    #from collections import defaultdict

    from itertools import combinations, permutations, accumulate, groupby

    #from itertools import product

    from bisect import bisect_left,bisect_right

    import heapq

    from math import floor, ceil

    #from operator import itemgetter



    #inf = 10**17

    #mod = 10**9 + 7



    N = int(eval(input()))

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

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

    res = 0

    n = 0

    for i in range(N):

        if a[i]<b[i]+n:

            res += a[i]

        else:

            res += b[i]+n

        if a[i]-n>0:

            c = a[i]-n

        else:

            c = 0

        if b[i]-c>0:

            n = b[i]-c

        else:

            n = 0

    res += min(n, a[-1])

    print(res)



if __name__ == '__main__':

    main()
def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby

    # from itertools import product
    from bisect import bisect_left, bisect_right
    import heapq
    from math import floor, ceil

    # from operator import itemgetter
    # inf = 10**17
    # mod = 10**9 + 7
    N = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    n = 0
    for i in range(N):
        res += min(a[i], b[i] + n)
        c = max(a[i] - n, 0)
        n = max(b[i] - c, 0)
    res += min(n, a[-1])
    print(res)


if __name__ == "__main__":
    main()

def main():
    import sys

    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque

    # from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby

    # from itertools import product
    from bisect import bisect_left, bisect_right
    import heapq
    from math import floor, ceil

    # from operator import itemgetter
    # inf = 10**17
    # mod = 10**9 + 7
    N = int(eval(input()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    n = 0
    for i in range(N):
        if a[i] < b[i] + n:
            res += a[i]
        else:
            res += b[i] + n
        if a[i] - n > 0:
            c = a[i] - n
        else:
            c = 0
        if b[i] - c > 0:
            n = b[i] - c
        else:
            n = 0
    res += min(n, a[-1])
    print(res)


if __name__ == "__main__":
    main()

-        res += min(a[i], b[i] + n) -        c = max(a[i] - n, 0) -        n = max(b[i] - c, 0) +        if a[i] < b[i] + n: +            res += a[i] +        else: +            res += b[i] + n +        if a[i] - n > 0: +            c = a[i] - n +        else: +            c = 0 +        if b[i] - c > 0: +            n = b[i] - c +        else: +            n = 0