#include <bits/stdc++.h>
using namespace std;
bool isValid(long long int n) {
  long long int last = 0;
  for (long long int i = 31; i >= 0; i--) {
    if (n & (1 << i) && last) return false;
    last = n & (1 << i);
  }
  return true;
}
void solve(long long int T) {
  long long int n;
  cin >> n;
  vector<long long int> arr(n);
  for (auto &i : arr) cin >> i;
  vector<long long int> brr(n);
  for (auto &i : brr) cin >> i;
  long long int ans = INT_MAX;
  for (long long int i = 1; i < n - 1; i++) {
    long long int left = INT_MAX;
    for (long long int j = 0; j < i; j++) {
      if (arr[i] > arr[j]) {
        left = min(left, brr[j]);
      }
    }
    long long int right = INT_MAX;
    for (long long int j = i + 1; j < n; j++) {
      if (arr[j] > arr[i]) {
        right = min(right, brr[j]);
      }
    }
    ans = min(ans, left + right + brr[i]);
  }
  if (ans >= INT_MAX) ans = -1;
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  for (long long int t = 1; t <= T; t++) {
    solve(t);
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
