#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<long long, long long>> tablo(n);
  for (int i = 0; i < n; ++i) {
    cin >> tablo[i].first;
  }
  for (int i = 0; i < n; ++i) {
    cin >> tablo[i].second;
  }
  long long res = LLONG_MAX;
  for (int ndx2 = 1; ndx2 < n - 1; ++ndx2) {
    long long tmp1 = LLONG_MAX, tmp3 = LLONG_MAX;
    ;
    for (int ndx1 = 0; ndx1 < ndx2; ++ndx1) {
      if (tablo[ndx1].first < tablo[ndx2].first) {
        tmp1 = min(tmp1, tablo[ndx1].second);
      }
    }
    for (int ndx3 = ndx2 + 1; ndx3 < n; ++ndx3) {
      if (tablo[ndx2].first < tablo[ndx3].first) {
        tmp3 = min(tmp3, tablo[ndx3].second);
      }
    }
    if (tmp1 < LLONG_MAX && tmp3 < LLONG_MAX) {
      res = min(res, tmp1 + tablo[ndx2].second + tmp3);
    }
  }
  if (res < LLONG_MAX) {
    cout << res;
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}
