#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n;
int a[3005], b[3005], m[3005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  long long minn = 1e18;
  for (int i = 1; i <= n; i++) {
    int minn = inf;
    int id = -1;
    for (int j = i + 1; j <= n; j++) {
      if (a[j] > a[i] && b[j] <= minn) {
        minn = min(minn, b[j]);
        id = j;
      }
    }
    m[i] = id;
  }
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      if (a[j] <= a[i]) continue;
      if (m[j] == -1) continue;
      minn = min(minn, (long long)b[i] + (long long)b[j] + (long long)b[m[j]]);
    }
  }
  if (minn == 1e18)
    cout << -1;
  else
    printf("%lld\n", minn);
  return 0;
}
