#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(12);
  int n;
  cin >> n;
  ;
  vector<int> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  ;
  vector<int> c(n);
  for (int i = 0; i < n; i++) cin >> c[i];
  ;
  vector<int> twos(n, inf);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) {
        twos[i] = min(twos[i], c[j] + c[i]);
      }
    }
  }
  vector<int> threes(n, inf);
  for (int i = 2; i < n; i++) {
    for (int j = 1; j < i; j++) {
      if (s[j] < s[i]) {
        threes[i] = min(threes[i], twos[j] + c[i]);
      }
    }
  }
  int result = inf;
  for (int i = 2; i < n; i++) {
    result = min(result, threes[i]);
  }
  if (result == inf)
    cout << -1 << endl;
  else
    cout << result << endl;
}
