#include <bits/stdc++.h>
using namespace std;
int tests;
string s;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  tests = 1;
  while (tests--) {
    long long n;
    cin >> n;
    long long s[n + 1], p[n + 1];
    for (int i = 1; i <= n; i++) cin >> s[i];
    for (int i = 1; i <= n; i++) cin >> p[i];
    long long ans = 1e18;
    for (int i = 1; i <= n; i++) {
      long long c1 = 1e18, c2 = 1e18;
      for (int j = 1; j < i; j++) {
        if (s[i] > s[j]) c1 = min(c1, p[j]);
      }
      for (int j = i + 1; j <= n; j++) {
        if (s[j] > s[i]) c2 = min(c2, p[j]);
      }
      ans = min(ans, c1 + c2 + p[i]);
    }
    if (ans < 1e18)
      cout << ans;
    else
      cout << -1;
  }
  return 0;
}
