from math import log2
import sys
import os
import io

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
output = sys.stdout.buffer.write
def print(*values, sep=' ', end='\n'):
    output(sep.join(str(value) for value in values).encode())
    output(encode())


def build(arr,n):
    for i in range(n):
        ls[i][0] = arr[i]
    j=1

    while (1<<j) <= n:
        i = 0
        while (i + (1<<j) -1 ) < n:
            if (ls[i][j-1][0] > ls[i+ (1<<(j-1))][j-1][0]):
                ls[i][j] = ls[i][j-1]
            else:
                ls[i][j] = ls[i+ (1<<(j-1))][j-1]
            i+=1
        j+=1

def query(L,R):
    j = int(log2(R-L+1))
    if ls[L][j][0] >= ls[R - (1<<j)+1][j][0]:
        return ls[L][j]
    else:
        return ls[R - (1<<j) +1][j]

import sys
sys.setrecursionlimit(10000)
def rec(l, r, sm):

    mx = l

    if l >= r-1:
        return sm + c[l]

    mx = query(l,r-1)[1]
    if mx == r-1 or mx == l :
        sm+= c[mx]
        return sm

    return min(rec(l, mx, sm + c[mx]), rec(mx + 1,r, sm + c[mx]))

vd = -1
def f(x):
    global vd
    vd+=1
    return int(x), vd

n = int(input())
h =list(map(f, input().split()))
c =list(map(int, input().split()))
ls = [[(-float('inf'),-float('inf'))] * n for _ in range(n)]


build(h, n)


print(rec(0, n, 0))

