#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long int arr[n], cost[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
  }
  long long int x = 100000000000;
  for (int i = 1; i < n - 1; i++) {
    long long int a = 100000000000, b = 100000000000;
    for (int j = 0; j < i; j++) {
      if (arr[j] < arr[i]) {
        a = min(cost[j], a);
      }
    }
    for (int j = i + 1; j < n; j++) {
      if (arr[j] > arr[i]) {
        b = min(cost[j], b);
      }
    }
    if (a == 100000000000 || b == 100000000000) continue;
    x = min(x, cost[i] + a + b);
  }
  if (x == 100000000000)
    cout << "-1\n";
  else
    cout << x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
