#include <bits/stdc++.h>
using namespace std;
int n;
int rez;
int v[3001], c[3001], dr[3001], dp[3001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = n; i >= 1; i--) {
    int sol = 1000000000, ind = 0;
    for (int j = i - 1; j >= 1; j--) {
      if (v[i] > v[j]) {
        if (sol > c[j]) {
          sol = c[j];
          ind = j;
        }
      }
    }
    dr[i] = ind;
    dp[i] = 1000000000;
  }
  for (int i = 3; i <= n; i++) {
    for (int j = 2; j < i; j++) {
      if (dr[j] && v[j] < v[i]) dp[i] = min(dp[i], c[i] + c[j] + c[dr[j]]);
    }
  }
  rez = 1000000000;
  for (int i = 1; i <= n; i++) rez = min(rez, dp[i]);
  if (rez != 1000000000)
    cout << rez;
  else
    cout << -1;
  return 0;
}
