#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[100003];
long long c[100003];
int main() {
  ios::sync_with_stdio(0), cin.tie();
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  map<long long, long long> m, cur;
  for (int i = 0; i < n; i++) {
    long long cost = c[i], mn = 1e15;
    for (int j = i + 1; j < n; j++) {
      if (a[i] < a[j]) mn = min(mn, c[j]);
    }
    if (mn != 1e15) m[i] = mn;
  }
  long long res = 1000000000000;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    long long cost = 1000000000000, mn = 1e10;
    for (int j = i + 1; j < n; j++) {
      if (a[i] < a[j] && m.find(j) != m.end())
        ok = true, cost = min(cost, c[i] + c[j] + m[j]);
    }
    res = min(res, cost);
  }
  if (!ok)
    cout << -1;
  else
    cout << res;
  return 0;
}
