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

left_cost = [float('inf')] * n
right_cost = [float('inf')] * n

# Calculate left_cost
left_cost[0] = costs[0]
for i in range(1, n):
    if heights[i] > heights[i - 1]:
        left_cost[i] = left_cost[i - 1] + costs[i]

# Calculate right_cost
right_cost[n - 1] = costs[n - 1]
for i in range(n - 2, -1, -1):
    if heights[i] > heights[i + 1]:
        right_cost[i] = right_cost[i + 1] + costs[i]

# Calculate minimum total cost
min_cost = min(left_cost[n - 1], right_cost[0])
for i in range(1, n - 1):
    min_cost = min(min_cost, left_cost[i] + right_cost[i])

print(min_cost)
