#include <bits/stdc++.h>
using namespace std;
long long res, x, y, ans, bit[5000], a[5000], b[5000];
int n, cnt;
pair<long long, int> c[5000];
void update(long long p, long long k) {
  for (long long i = p; i <= cnt; i += (i & -i)) bit[i] = min(bit[i], k);
}
long long get(long long p) {
  ans = LLONG_MAX;
  for (long long i = p; i > 0; i -= (i & -i)) ans = min(ans, bit[i]);
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[i].first = a[i];
    c[i].second = i;
    bit[i] = LLONG_MAX;
  }
  sort(c + 1, c + n + 1);
  cnt = 1;
  a[c[1].second] = 1;
  for (int i = 2; i <= n; i++) {
    if (c[i].first > c[i - 1].first) cnt++;
    a[c[i].second] = cnt;
  }
  for (int i = 1; i <= n; i++) cin >> b[i];
  update(a[1], b[1]);
  res = LLONG_MAX;
  for (int i = 2; i <= n; i++) {
    long long jj = get(a[i] - 1);
    if (jj != LLONG_MAX) {
      for (int j = i + 1; j <= n; j++) {
        if (a[j] > a[i]) {
          res = min(res, jj + b[i] + b[j]);
        }
      }
    }
    update(a[i], b[i]);
  }
  if (res != LLONG_MAX)
    cout << res;
  else
    cout << -1;
}
