n = int(input())
h = list(map(int, input().split()))
c = list(map(int, input().split()))

d = [float('inf')] * n
d[0] = 0

for i in range(1, n):
    for j in range(i):
        if h[i] > h[j]:
            d[i] = min(d[i], d[j] + c[i])

print(d[n-1])
