#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
long long dp[N][3];
int n;
int a[N];
int c[N];
long long solve(int idx, int status) {
  if (status == 3) return 0;
  if (idx > n) return (long long)1e18;
  if (dp[idx][status] != -1) return dp[idx][status];
  long long rekt = (long long)1e18;
  if (status == 2) {
    return dp[idx][status] = c[idx];
  }
  for (int j = idx + 1; j <= n; ++j) {
    if (a[j] > a[idx]) {
      rekt = min(rekt, c[idx] + solve(j, status + 1));
    }
  }
  return dp[idx][status] = rekt;
}
int main() {
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> c[i];
  long long ans = (long long)1e18;
  for (int i = 1; i <= n; ++i) {
    ans = min(ans, solve(i, 0));
  }
  if (ans == (long long)1e18) {
    ans = -1;
  }
  cout << ans;
  return 0;
}
