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

dp = [0] * (n+1)
dp[1] = costs[0]

for i in range(2, n+1):
    max_height = heights[i-1]
    min_cost = dp[i-1] + costs[i-1]
    
    for j in range(i-1, 0, -1):
        if heights[j-1] > max_height:
            max_height = heights[j-1]
            min_cost = min(min_cost, dp[j-1] + costs[i-1])
    
    dp[i] = min_cost

print(dp[n])