#include <bits/stdc++.h>
using namespace std;
long long ar[3001], br[3001];
long long MAX = 10000000000000;
long long dp[3001][3];
long long min(long long a, long long b) { return a <= b ? a : b; }
long long solve(int i, int n, int cnt, int p1) {
  long long res = MAX;
  for (int j = 0; j < n; j++) {
    for (int k = j - 1; k >= 0; k--) {
      if (ar[j] > ar[k]) {
        if (k >= 0) dp[j][1] = min(dp[j][1], dp[j][0] + dp[k][0]);
        if (k >= 1) {
          dp[j][2] = min(dp[j][2], br[j] + dp[k][1]);
          res = min(res, dp[j][2]);
        }
      }
    }
  }
  return res;
}
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 0; i < n; i++) cin >> br[i];
  for (int i = 0; i <= n; i++)
    for (int j = 1; j < 3; j++) {
      dp[i][j] = MAX;
      dp[i][0] = br[i];
    }
  long long ans = solve(0, n, 0, -1);
  if (ans == MAX)
    cout << "-1\n";
  else
    cout << ans << "\n";
  return 0;
}
