#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long s[n];
  long long c[n];
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < n; i++) cin >> c[i];
  long long cost[n];
  for (long long i = 0; i < n; i++) cost[i] = -1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[j] > s[i]) {
        if (cost[j] == -1)
          cost[j] = c[i] + c[j];
        else
          cost[j] = min(cost[j], c[i] + c[j]);
      }
    }
  }
  long long dp[n];
  for (long long i = 0; i < n; i++) dp[i] = -1;
  for (long long i = 0; i < n; i++) {
    if (cost[i] == -1) continue;
    for (long long j = i + 1; j < n; j++) {
      if (s[j] > s[i]) {
        if (dp[j] == -1)
          dp[j] = cost[i] + c[j];
        else
          dp[j] = min(dp[j], cost[i] + c[j]);
      }
    }
  }
  long long ans = INT_MAX;
  for (long long i = 0; i < n; i++)
    if (dp[i] != -1) ans = min(ans, dp[i]);
  if (ans != INT_MAX)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
