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

left_to_right = [0] * n
right_to_left = [0] * n
stack = []

# Проход слева направо
for i in range(n):
    while stack and heights[stack[-1]] < heights[i]:
        stack.pop()
    if stack:
        left_to_right[i] = costs[i] + costs[stack[-1]]
    else:
        left_to_right[i] = costs[i]
    stack.append(i)

# Проход справа налево
stack = []
for i in range(n - 1, -1, -1):
    while stack and heights[stack[-1]] < heights[i]:
        stack.pop()
    if stack:
        right_to_left[i] = costs[i] + costs[stack[-1]]
    else:
        right_to_left[i] = costs[i]
    stack.append(i)

# Найти минимальную стоимость
min_cost = float('inf')
for i in range(n):
    min_cost = min(min_cost, left_to_right[i] + right_to_left[i] - costs[i])

print(min_cost)
