#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  map<long long, long long> mp[3];
  long long n;
  cin >> n;
  long long s[n], 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 dp[n];
  for (long long i = 0; i < n; i++) {
    dp[i] = 1e17 + 3;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (s[j] > s[i]) {
        dp[i] = min(dp[i], c[i] + c[j]);
      }
    }
  }
  long long ans = 1e17 + 3;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      if ((dp[j] == 1e17 + 3) || (s[j] <= s[i])) continue;
      ans = min(ans, c[i] + dp[j]);
    }
  }
  if (ans == 1e17 + 3) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
  return 0;
}
