#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pair<int, int>> vec(n);
  for (int i = 0; i < n; ++i) cin >> vec[i].first;
  for (int i = 0; i < n; ++i) cin >> vec[i].second;
  int ans = 1e9;
  for (int i = 1; i < n; ++i) {
    int it = -1;
    for (int j = 0; j < i; ++j) {
      if (vec[j].first >= vec[i].first) continue;
      if (it == -1 || vec[j].second < vec[it].second) it = j;
    }
    if (it == -1) continue;
    int cnt = vec[it].second;
    it = -1;
    for (int j = i + 1; j < n; ++j) {
      if (vec[j].first <= vec[i].first) continue;
      if (it == -1 || vec[j].second < vec[it].second) it = j;
    }
    if (it != -1) {
      ans = min(ans, cnt + vec[it].second + vec[i].second);
    }
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
  return 0;
}
