#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int arr[n][2], cost[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i][0];
  }
  for (int i = 0; i < n; i++) cin >> cost[i];
  for (int i = 0; i < n; i++) arr[i][1] = -1;
  for (int i = 0; i < n; i++) {
    long long int min = 1000000000000000000;
    for (int j = i + 1; j < n; j++) {
      if (arr[i][0] < arr[j][0] && cost[j] < min) min = cost[j];
    }
    arr[i][1] = min;
  }
  if (n == 3) {
    if ((arr[0][0] < arr[1][0]) && (arr[1][0] < arr[2][0]))
      return cout << cost[0] + cost[1] + cost[2], 0;
    else
      return cout << -1, 0;
  }
  long long int ans = 1000000000000000000;
  for (int i = 0; i < n - 2; i++) {
    long long int c = cost[i];
    for (int j = i + 1; j < n - 1; j++) {
      int f = 0;
      if (arr[j][0] > arr[i][0] && arr[j][0] != -1) {
        c += cost[j] + arr[j][1];
        f = 1;
      }
      if (c < ans && f == 1) ans = c;
      c = cost[i];
    }
  }
  ans == 1000000000000000000 ? cout << -1 : cout << ans;
}
