#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
const long long inf = 0x7fffffffffffffff;
const long long infneg = -0x7fffffffffffffff;
int sizes[3005];
int price[3005];
int dp[3][3005];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> sizes[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> price[i];
  }
  for (int i = 0; i < n; i++) {
    dp[0][i] = price[i];
  }
  for (int k = 1; k < 3; k++) {
    for (int i = 0; i < n; i++) {
      int tmp = -1;
      for (int j = 0; j < i; j++) {
        if (dp[k - 1][j] != -1 && sizes[j] < sizes[i]) {
          if (tmp == -1) {
            tmp = dp[k - 1][j] + price[i];
          } else {
            tmp = min(tmp, dp[k - 1][j] + price[i]);
          }
        }
      }
      dp[k][i] = tmp;
    }
  }
  int out = -1;
  for (int i = 0; i < n; i++) {
    if (out == -1) {
      out = dp[2][i];
    } else if (dp[2][i] != -1) {
      out = min(out, dp[2][i]);
    }
  }
  cout << out;
}
