#include <bits/stdc++.h>
using namespace std;
long long int sum = 0;
long long int ff(long long int cur, long long int x) {
  if (cur - x > 0)
    return cur - x;
  else
    return cur + x;
}
vector<int> P;
void kFactors(int n, int k) {
  while (n % 2 == 0) {
    P.push_back(2);
    n /= 2;
  }
  for (int i = 3; i * i <= n; i = i + 2) {
    while (n % i == 0) {
      n = n / i;
      P.push_back(i);
    }
  }
  if (n > 2) P.push_back(n);
}
void jai_mata_di() {
  long long int i, x, j, k, y, p, q, r, w, sum = 0, cnt = 0, flag = 1;
  long long int n;
  cin >> n;
  long long int dp[n + 1];
  long long int a[n];
  long long int b[n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  for (i = 0; i < n - 1; i++) {
    long long int mn = 1e13;
    for (j = i + 1; j < n; j++) {
      if (a[i] < a[j]) mn = min(mn, b[j]);
    }
    dp[i] = mn;
  }
  long long int mn = 1e13;
  for (i = 0; i < n - 2; i++) {
    for (j = i + 1; j < n - 1; j++) {
      if (a[i] < a[j]) {
        if (dp[j] != 1e13) {
          mn = min(mn, dp[j] + b[i] + b[j]);
        }
      }
    }
  }
  if (mn == 1e13)
    cout << -1;
  else
    cout << mn;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tt = 1.0 * clock();
  int t;
  t = 1;
  for (int y = 0; y < t; y++) {
    jai_mata_di();
    cout << endl;
  }
  return 0;
}
