#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
int minrent(int s[], int c[], int n) {
  int best = inf;
  for (int j = 1; j <= n - 2; j++) {
    int elei = -1, elek = -1;
    for (int i = 0; i < j; i++) {
      if (s[i] < s[j] && (elei == -1 || c[elei] > c[i])) {
        elei = i;
      }
    }
    if (elei == -1) continue;
    for (int k = j + 1; k < n; k++) {
      if (s[j] < s[k] && (elek == -1 || c[elek] > c[k])) {
        elek = k;
      }
    }
    if (elek == -1) continue;
    best = min(best, c[elei] + c[j] + c[elek]);
  }
  if (best >= inf) return -1;
  return best;
}
int main() {
  int n;
  cin >> n;
  int s[n], c[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  cout << minrent(s, c, n) << endl;
}
