#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 111;
const int maxn = 3e3 + 10;
int n, s[maxn], c[maxn];
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  int ans = mod;
  for (int i = 1; i < n - 1; i++) {
    int temp = c[i];
    int l = mod;
    int r = mod;
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) {
        l = min(l, c[j]);
      }
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] > s[i]) {
        r = min(r, c[j]);
      }
    }
    temp += (r + l);
    ans = min(ans, temp);
  }
  if (ans == mod) {
    cout << -1;
    return 0;
  }
  cout << ans;
}
