#include <bits/stdc++.h>
const int inf = 2e3;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long sum, n, l, cnt, cmt, mn, m = LONG_MAX;
  cin >> n;
  bool ok = false;
  long long s[n], c[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++) {
    sum = c[i];
    l = s[i];
    cnt = cmt = 0;
    mn = LONG_MAX;
    for (int j = i - 1; j >= 0; j--) {
      if (s[j] < l) {
        cmt = 1;
        mn = min(mn, c[j]);
      }
    }
    if (cmt) sum += mn;
    mn = LONG_MAX;
    for (int j = i + 1; j < n; j++) {
      if (s[j] > l) {
        cnt = 1;
        mn = min(mn, c[j]);
      }
    }
    if (cnt) sum += mn;
    if (cnt && cmt) {
      ok = true;
      m = min(m, sum);
    }
  }
  if (!ok)
    cout << -1 << '\n';
  else
    cout << m << '\n';
  return 0;
}
