#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> sz;
vector<long long> price;
int main() {
  long long tmp;
  long long ans = 10e9;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> tmp;
    sz.push_back(tmp);
  }
  for (long long i = 0; i < n; ++i) {
    cin >> tmp;
    price.push_back(tmp);
  }
  for (long long j = 1; j < n - 1; ++j) {
    long long min_i = 10e9, min_k = 10e9;
    for (long long i = 0; i < j; ++i) {
      if (sz[i] < sz[j]) min_i = min(min_i, price[i]);
    }
    for (long long k = j + 1; k < n; ++k) {
      if (sz[k] > sz[j]) min_k = min(min_k, price[k]);
    }
    ans = min(ans, min_i + min_k + price[j]);
  }
  if (ans > 3 * 10e8) {
    cout << -1;
    return 0;
  }
  cout << ans;
  return 0;
}
