#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  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];
  long long s0, s1, s2, ans = 1e18;
  for (int j = 1; j < n; j++) {
    bool f1 = 0, f2 = 0;
    s0 = c[j];
    s1 = 1e10;
    s2 = 1e10;
    for (int i = j - 1; i >= 0; i--) {
      if (s[i] < s[j]) {
        f1 = 1;
        s1 = min(s1, c[i]);
      }
    }
    for (int k = j + 1; k < n; k++) {
      if (s[k] > s[j]) {
        f2 = 1;
        s2 = min(s2, c[k]);
      }
    }
    if (f1 == 1 && f2 == 1) {
      ans = min(ans, s0 + s1 + s2);
    }
  }
  if (ans == 1e18) ans = -1;
  cout << ans << endl;
}
