#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int maxn = 3e3 + 6;
const double eps = 1e-6;
using namespace std;
bool eq(const double &a, const double &b) { return fabs(a - b) < eps; }
bool ls(const double &a, const double &b) { return a + eps < b; }
bool le(const double &a, const double &b) { return eq(a, b) || ls(a, b); }
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); };
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long kpow(long long a, long long b) {
  long long res = 1;
  if (b < 0) return 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long dp[maxn][6];
struct E {
  long long s, c;
} e[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < (n + 1); ++i)
    for (int j = 0; j < (3 + 1); ++j) dp[i][j] = 0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i < (n + 1); ++i) scanf("%lld", &e[i].s);
  for (int i = 1; i < (n + 1); ++i) scanf("%lld", &e[i].c);
  dp[1][1] = e[1].c;
  for (int i = 2; i < (n + 1); ++i) {
    dp[i][1] = e[i].c;
    for (int j = 1; j < (i); ++j) {
      for (int k = 2; k < (3 + 1); ++k) {
        if (e[i].s > e[j].s) dp[i][k] = min(dp[i][k], dp[j][k - 1] + e[i].c);
      }
    }
  }
  long long ans = 0x3f3f3f3f3f3f3f3f;
  for (int i = 3; i < (n + 1); ++i) ans = min(ans, dp[i][3]);
  printf("%lld\n", ans == 0x3f3f3f3f3f3f3f3f ? -1 : ans);
  return 0;
}
