#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 3005;
const long long INF = 1e18;
int s[MAXN], c[MAXN];
long long dp[4][MAXN];
long long cost = INF;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < MAXN; j++) {
      dp[i][j] = INF;
    }
  }
  for (int i = 0; i < n; i++) {
    dp[1][i] = c[i];
  }
  for (int i = 2; i <= 3; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = j - 1; k >= 0; k--) {
        if (s[k] < s[j] && dp[i - 1][k] != INF) {
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + c[j]);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cost = min(cost, dp[3][i]);
  }
  if (cost == INF) cost = -1;
  cout << cost;
}
