# 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())

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

    mx = 0

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

    for i in range(l, r):
        if h[mx] < h[i]:
            mx = i

    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]))

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

print(rec(0, n, 0))
