#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, n;
  cin >> n;
  long long int a[n], b[n];
  long long int minl = INT_MAX, minr = INT_MAX, sum = INT_MAX;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) cin >> b[i];
  if (n < 3)
    cout << -1;
  else {
    for (j = 1; j < n - 1; j++) {
      minl = INT_MAX;
      minr = INT_MAX;
      for (i = 0; i < j; i++)
        if (a[i] < a[j]) minl = min(minl, b[i]);
      for (k = j + 1; k < n; k++)
        if (a[k] > a[j]) minr = min(minr, b[k]);
      if (minl != INT_MAX && minr != INT_MAX) {
        if (sum > minl + b[j] + minr) sum = minl + b[j] + minr;
      }
    }
  }
  if (sum != INT_MAX)
    cout << sum;
  else
    cout << -1;
  return 0;
}
