#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 7;
int n;
long long s[maxn], c[maxn], val[maxn];
bool vis[maxn];
int main() {
  while (~scanf("%d", &n)) {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++) scanf("%lld", &s[i]);
    for (int i = 0; i < n; i++) scanf("%lld", &c[i]);
    for (int j = 0; j < n; j++) {
      long long m = 0x3f3f3f3f;
      val[j] = c[j];
      for (int k = j - 1; k >= 0; k--) {
        if (s[j] > s[k]) {
          m = min(m, c[k]);
        }
      }
      if (m != 0x3f3f3f3f) {
        vis[j] = true;
        val[j] += m;
      }
    }
    long long ans = 999999999999999;
    for (int j = 0; j < n; j++) {
      if (!vis[j]) continue;
      for (int k = j + 1; k < n; k++) {
        if (s[j] < s[k]) {
          ans = min(ans, val[j] + c[k]);
        }
      }
    }
    if (ans == 999999999999999)
      printf("-1\n");
    else
      printf("%lld\n", ans);
  }
  return 0;
}
