#include <bits/stdc++.h>
using namespace std;
int n, a[3000], c[3000], d[3000], m;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    m = 0x3f3f3f3f;
    for (int j = 0; j < i; j++) {
      if (a[j] < a[i]) m = min(m, c[j] + c[i]);
    }
    d[i] = m;
  }
  m = 0x3f3f3f3f;
  for (int i = 2; i < n; i++) {
    for (int j = 1; j < i; j++) {
      if (a[j] < a[i]) m = min(m, c[i] + d[j]);
    }
  }
  if (m < 0x3f3f3f3f)
    cout << m;
  else
    cout << -1;
}
