#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  vector<long long> f(n + 1);
  vector<long long> dp(n + 1, -1);
  for (long long i = 1; i <= n; ++i) {
    cin >> f[i];
  }
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  long long ans = inf;
  for (long long i = 1; i <= n; ++i) {
    long long res1 = inf, res2 = inf;
    long long j = i, k = i;
    while (j > 0) {
      if (f[j] < f[i]) res1 = min(res1, a[j]);
      --j;
    }
    while (k <= n) {
      if (f[k] > f[i]) res2 = min(res2, a[k]);
      ++k;
    }
    ans = min(ans, res1 + res2 + a[i]);
  }
  cout << (ans == inf ? -1 : ans);
}
