import sys
sys.setrecursionlimit(200000)
n = int(input())
h = list(map(int, input().split()))
c = list(map(int, input().split()))
def f(l, r):
    if l >= r:
        return 0
    h_max = l
    for i in range(l + 1, r):
        if h[i] > h[h_max]:
            h_max = i
    return min(f(l, h_max), f(h_max + 1, r)) + c[h_max]
print(f(0, n))