import sys
n = int(input())
sys.setrecursionlimit(n + 100)
h = list(map(int, input().split()))
c = list(map(int, input().split()))
def get(i):
    if i < 0 or i >= n:
        while True:
            pass
    return h[i]
def f(l, r):
    '''if x > 1000:
        while True:
            pass'''
    if l >= r:
        return 0
    h_max = l
    for i in range(l + 1, r):
        if get(i) > get(h_max):
            h_max = i
    c_max = c[h_max]
    if h_max == l or h_max == r - 1:
        return c_max
    return min(f(l, h_max), f(h_max + 1, r)) + c_max
print(f(0, n))