def f(a, b, x):
    maxx = 0
    maxi = -1
    for i in range(a, b):
        if h[i - 1] > maxx:
            maxx = h[i - 1]
            maxi = i - 1
    sp[x] += c[maxi]
    if b - a > 1:
        y = max(s) + 1
        s.add(y)
        sp[y] += sp[x]
        f(maxi + 1, b, y)
        f(a, maxi - 1, x)




n = int(input())
h = list(map(int, input().split()))
c = list(map(int, input().split()))
s = set()
s.add(1)
sp = [0] * (2 * n + 1)
f(1, n, 1)
sp2 = set(sp)
sp2.discard(0)
print(min(sp2))
