#include <bits/stdc++.h>
using namespace std;
long long font[3005];
long long val[3005];
map<long long, long long> mymap;
map<long long, long long> comp;
map<long long, long long>::iterator it;
long long bit[2][3005];
void update(long long typ, long long idx, long long val) {
  while (idx <= 3005) {
    bit[typ][idx] = min(bit[typ][idx], val);
    idx += (idx & -idx);
  }
}
long long query(long long typ, long long idx) {
  long long res = 1e12;
  while (idx) {
    res = min(bit[typ][idx], res);
    idx -= (idx & -idx);
  }
  return res;
}
int main() {
  long long n, i, j;
  cin >> n;
  for (i = 0; i <= 3005; i++) bit[0][i] = 1e12;
  for (i = 0; i < n; i++) cin >> font[i];
  for (i = 0; i < n; i++) cin >> val[i];
  for (i = 0; i < n; i++) mymap[font[i]];
  long long idx = 1;
  for (it = mymap.begin(); it != mymap.end(); it++) {
    comp[it->first] = idx++;
  }
  long long flag = 0;
  long long ans = 1e12;
  update(0, comp[font[0]], val[0]);
  for (i = 1; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (font[i] < font[j]) {
        long long temp = query(0, comp[font[i]] - 1);
        if (temp != 1e12) {
          flag = 1;
          ans = min(ans, temp + val[i] + val[j]);
        }
      }
    }
    update(0, comp[font[i]], val[i]);
  }
  if (flag && ans != 1e12)
    cout << ans;
  else
    cout << -1;
  return 0;
}
