#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005, INF = 1e9;
int n, s[MAXN], c[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", s + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", c + i);
  }
  int ans = INF;
  for (int i = 1; i < n - 1; ++i) {
    int minl = INF, minr = INF;
    for (int j = 0; j < i; ++j) {
      if (s[j] < s[i]) {
        minl = min(minl, c[j]);
      }
    }
    for (int j = i + 1; j < n; ++j) {
      if (s[j] > s[i]) {
        minr = min(minr, c[j]);
      }
    }
    if (minl != INF && minr != INF) {
      ans = min(ans, minl + minr + c[i]);
    }
  }
  if (ans == INF) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}
