#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
long long int dx[] = {0, 0, 1, -1};
long long int dy[] = {1, -1, 0, 0};
const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
long long int dp[2][3010][4];
signed main() {
  long long int N;
  scanf("%lld", &N);
  vector<long long int> S(N), C(N);
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
  }
  fill(dp[0][0], dp[2][0], INF);
  dp[0][0][0] = 0;
  for (long long int i = 0; i < N; i++) {
    long long int cur = i % 2, nxt = 1 - cur;
    for (long long int j = 0; j <= i; j++) {
      for (long long int k = 0; k <= 3; k++) {
        long long int pre = (j == 0 ? 0 : S[j - 1]);
        if (k + 1 <= 3 && pre < S[i]) {
          chmin(dp[nxt][i + 1][k + 1], dp[cur][j][k] + C[i]);
        }
        chmin(dp[nxt][j][k], dp[cur][j][k]);
        dp[cur][j][k] = INF;
      }
    }
  }
  long long int ans = INF;
  for (long long int i = 0; i <= N; i++) {
    chmin(ans, dp[N % 2][i][3]);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
