#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
int n;
bool ok = false;
long long s[N];
long long c[N];
long long l[N], r[N];
long long res;
long long tmp;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 2; i < n; i++) {
    tmp = 1e18 + 1;
    for (int j = 1; j < i; j++) {
      if (s[j] < s[i]) tmp = min(tmp, c[j]);
    }
    if (tmp != 1e18 + 1) l[i] = tmp;
    tmp = 1e18 + 1;
    for (int j = i + 1; j <= n; j++) {
      if (s[i] < s[j]) tmp = min(tmp, c[j]);
    }
    if (tmp != 1e18 + 1) r[i] = tmp;
  }
  res = 3e18;
  for (int i = 2; i < n; i++) {
    if (l[i] == 0 || r[i] == 0) continue;
    ok = true;
    res = min(res, l[i] + r[i] + c[i]);
  }
  if (!ok)
    cout << -1;
  else
    cout << res;
  return 0;
}
