#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int font[3002];
  int cost[3002];
  int af[3002];
  for (int i = 0; i < n; i++) {
    cin >> font[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int lw = 100000001;
    int idx = -1;
    for (int j = i + 1; j < n; j++) {
      if (font[j] > font[i] && cost[j] < lw) {
        idx = j;
        lw = cost[j];
      }
    }
    af[i] = idx;
  }
  int mincost = 2000000000;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      if (font[i] < font[j]) {
        int sum = cost[i] + cost[j];
        if (af[j] != -1) {
          sum += cost[af[j]];
          if (sum < mincost) mincost = sum;
        }
      }
    }
  }
  if (mincost != 2000000000)
    cout << mincost;
  else
    cout << -1;
  return 0;
}
