#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long int arr[n], brr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> brr[i];
  }
  long long int ans = 1e9;
  for (int i = 1; i < n - 1; i++) {
    long long int leftinc = 1e9, rightinc = 1e9;
    for (int j = 0; j < i; j++) {
      if (arr[i] > arr[j]) {
        leftinc = min(leftinc, brr[j]);
      }
    }
    for (int j = i + 1; j < n; j++) {
      if (arr[j] > arr[i]) rightinc = min(rightinc, brr[j]);
    }
    ans = min(ans, leftinc + rightinc + brr[i]);
  }
  ans = (ans == 1e9 ? -1 : ans);
  cout << ans;
}
