#include <bits/stdc++.h>
using namespace std;
long long a[3001] = {}, c[3001] = {};
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  long long ct = INT_MAX;
  for (int i = 1; i < n - 1; i++) {
    long long r = INT_MAX;
    bool f = 0;
    for (int j = 0; j < i; j++) {
      if (a[j] < a[i]) {
        f = 1;
        r = min(r, c[j]);
      }
    }
    if (f == 0) continue;
    f = 0;
    long long g = INT_MAX;
    for (int j = i + 1; j < n; j++) {
      if (a[j] > a[i]) {
        f = 1;
        g = min(g, c[j]);
      }
    }
    if (f == 0) continue;
    ct = min(ct, (c[i] + r + g));
  }
  if (ct == INT_MAX)
    cout << "-1\n";
  else
    cout << ct;
}
