#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 11, mod = 1e9 + 7;
const int INF1 = 2e9;
const long long INF2 = 2e18;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const double EPS = 1e-9;
const double PI = acos(-1.0);
int n, a[N], c[N];
long long ans = INF2, dp[N][5];
int main() {
  if (fopen("queue"
            ".in",
            "r"))
    freopen(
        "queue"
        ".in",
        "r", stdin),
        freopen(
            "queue"
            ".out",
            "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i += 1) cin >> a[i];
  for (int i = 1; i <= n; i += 1) cin >> c[i];
  for (int i = 1; i <= n; i += 1) {
    dp[i][1] = c[i];
    dp[i][2] = dp[i][3] = INF2;
    for (int j = i - 1; j >= 1; j -= 1) {
      if (a[i] > a[j]) {
        dp[i][2] = min(dp[i][2], dp[j][1] + c[i]);
        dp[i][3] = min(dp[i][3], dp[j][2] + c[i]);
      }
    }
    ans = min(ans, dp[i][3]);
  }
  if (ans == INF2)
    cout << -1;
  else
    cout << ans;
  return 0;
}
