#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int main() {
  int n;
  cin >> n;
  long long s[n + 5], c[n + 5];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  long long si, sj, sk, ans = 9000000000000000000;
  for (int i = 1; i < n - 1; i++) {
    si = sk = 9000000000000000000;
    sj = c[i];
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) si = min(si, c[j]);
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] > s[i]) sk = min(sk, c[j]);
    }
    {
      string _s = "si, sj, sk";
      replace(_s.begin(), _s.end(), ',', ' ');
      stringstream _ss(_s);
      istream_iterator<string> _it(_ss);
      err(_it, si, sj, sk);
    };
    ans = min(ans, (si + sj + sk));
  }
  if (ans == 9000000000000000000)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
