#include <bits/stdc++.h>
using namespace std;
long long n, m, a[100005], b[100005], x, y, v, t, i, j, k;
string s;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long ans = 100000000005;
  for (i = 1; i < n - 1; i++) {
    x = 100000000005;
    y = 100000000005;
    v = 0;
    t = 0;
    for (j = i - 1; j >= 0; j--) {
      if (b[j] < x && a[i] > a[j]) {
        x = b[j];
        v = j;
      }
    }
    for (j = i + 1; j < n; j++) {
      if (b[j] < y && a[i] < a[j]) {
        y = b[j];
        t = j;
      }
    }
    if (x != 100000000005 && y != 100000000005 && ans > b[i] + b[v] + b[t]) {
      ans = b[i] + b[v] + b[t];
    }
  }
  if (ans == 100000000005) ans = -1;
  cout << ans;
}
