#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[3005], b[3005];
  int n, i, j, k, m, ans = 1000000000;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= n; ++i) cin >> b[i];
  b[0] = 1000000000;
  b[n + 1] = 1000000000;
  for (i = 1; i <= n; ++i) {
    int l = 0;
    int r = n + 1;
    for (j = 1; j < i; ++j) {
      if (a[j] < a[i]) {
        if (b[j] < b[l]) l = j;
      }
    }
    for (j = i + 1; j <= n; ++j) {
      if (a[j] > a[i]) {
        if (b[j] < b[r]) r = j;
      }
    }
    if (l != 0 && r != n + 1) ans = min(ans, b[i] + b[l] + b[r]);
  }
  if (ans == 1000000000) {
    cout << -1;
    return 0;
  } else
    cout << ans;
  return 0;
}
