#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int S[n], C[n];
  for (int i = 0; i < n; i++) cin >> S[i];
  for (int i = 0; i < n; i++) cin >> C[i];
  long long int mina, minb, min = INT_MAX, sum, a, b, c;
  bool founda = false, foundb = false;
  for (int i = 1; i < (n - 1); i++) {
    mina = INT_MAX;
    for (int j = i - 1; j >= 0; j--) {
      if (S[i] > S[j]) {
        founda = true;
        if (C[j] < mina) {
          a = j;
          mina = C[j];
        }
      }
    }
    minb = INT_MAX;
    for (int j = i + 1; j < n; j++) {
      if (S[i] < S[j]) {
        foundb = true;
        if (C[j] < minb) {
          c = j;
          minb = C[j];
        }
      }
    }
    sum = C[i] + mina + minb;
    if (sum < min) {
      b = i;
      min = sum;
    }
  }
  if (!(founda && foundb))
    cout << -1;
  else {
    cout << min;
  }
  return 0;
}
