#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, s[3005], c[3005];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  long long int ans = INT_MAX;
  for (int i = 1; i < n - 1; i++) {
    long long int p = INT_MAX, q = INT_MAX;
    for (int j = 0; j < i; j++)
      if (s[j] < s[i]) p = min(p, c[j]);
    for (int j = i + 1; j < n; j++)
      if (s[j] > s[i]) q = min(q, c[j]);
    ans = min(ans, c[i] + p + q);
  }
  if (ans - INT_MAX)
    cout << ans << endl;
  else
    cout << "-1\n";
  return 0;
}
