n = int(input())
heights = list(map(int, input().split()))
costs = list(map(int, input().split()))

dp = [0] * n
dp[0] = costs[0]

for i in range(1, n):
    dp[i] = float('inf')
    for j in range(i):
        if heights[i] > heights[j]:
            dp[i] = min(dp[i], dp[j] + costs[i])

print(dp[-1])
