#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int pos, p, q, m, i, j, x, y, e, t, T, ans, cnt, mn, sum, mx, f, c,
      k, l, r;
  long long int n;
  bool flag;
  t = 1;
  while (t--) {
    long long int mn1, mn2;
    mn = LLONG_MAX;
    cin >> n;
    long long int a1[3005], a2[3005];
    for (long long int i = 0; i < n; i++) cin >> a1[i];
    for (long long int i = 0; i < n; i++) cin >> a2[i];
    for (i = 1; i < n - 1; i++) {
      mn1 = LLONG_MAX;
      mn2 = LLONG_MAX;
      sum = a2[i];
      for (j = i - 1; j >= 0; j--)
        if (a1[j] < a1[i]) mn1 = min(mn1, a2[j]);
      for (j = i + 1; j < n; j++)
        if (a1[j] > a1[i]) mn2 = min(mn2, a2[j]);
      if (mn1 != LLONG_MAX && mn2 != LLONG_MAX) mn = min(mn, sum + mn1 + mn2);
    }
    if (mn == LLONG_MAX)
      cout << -1;
    else
      cout << mn;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
