#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zeroupper")
#pragma GCC target("avx", "popcnt")
using namespace std;
const long long int INF = (long long int)1e17 + 5;
const unsigned long long int MOD = 1e8 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  std::cout << std::fixed;
  std::cout.precision(6);
  int n;
  cin >> n;
  vector<pair<long long int, long long int>> v;
  for (int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    v.emplace_back(make_pair(a, 0));
  }
  for (int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    v[i].second = a;
  }
  long long int mini = INF;
  int pos = 0;
  for (int j = 1; j < n - 1; j++) {
    long long int minl = INF;
    long long int minr = INF;
    for (int i = j - 1; i >= 0; i--) {
      if (v[i].first < v[j].first) minl = min(minl, v[i].second);
    }
    for (int i = j + 1; i < n; i++) {
      if (v[i].first > v[j].first) minr = min(minr, v[i].second);
    }
    if (minl != INF && minr != INF) {
      long long int l = v[j].second + minr + minl;
      mini = min(mini, l);
    }
  }
  if (mini == INF)
    cout << "-1\n";
  else
    cout << mini << "\n";
  return 0;
}
