#include <iostream>
import sys

n = int(input())

heights = list(map(int, input().split()))
price = list(map(int, input().split()))

dp = [sys.maxsize] * n

dp[0] = price[0]

for i in range(1, n):
    dp[i] = dp[i - 1] + price[i]
    maxh = heights[i]

    for j in range(i - 1, -1, -1):
        if heights[j] > maxh:
            break
        maxh = max(maxh, heights[j])
        if j == 0:
            dp[i] = min(dp[i], price[i])
        else:
            dp[i] = min(dp[i], dp[j - 1] + price[i])

print(dp[-1])