#include <bits/stdc++.h>
using namespace std;
int s[3010], c[3010];
int dp[3010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int j = 0; j < n; j++) cin >> c[j];
  for (int i = 0; i <= n + 1; i++) dp[i] = (1 << 30);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) dp[i] = min(dp[i], c[j] + c[i]);
    }
  }
  int mn = (1 << 30);
  for (int i = 2; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) mn = min(mn, dp[j] + c[i]);
    }
  }
  if (mn == (1 << 30))
    cout << -1 << '\n';
  else
    cout << mn << '\n';
  return 0;
}
