#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debugv(vector<vector<T>> v) {
  for (auto x : v) {
    for (auto y : x) {
      cout << y << " ";
    }
    cout << "\n";
  }
}
template <typename T>
T myMax(T x, T y) {
  return (x > y) ? x : y;
}
long long maximum = numeric_limits<int>::max();
long long minimum = numeric_limits<int>::min();
string gg = "abcdefghijklmnopqrstuvwxyz";
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int mint(int x, int y, int z) {
  if (x < y)
    return (x < z) ? x : z;
  else
    return (y < z) ? y : z;
}
vector<pair<long long int, long long int>> v;
bool sortbysec(const pair<long long int, long long int>& a,
               const pair<long long int, long long int>& b) {
  if (a.second == b.second) {
    return (a.first > b.first);
  }
  return a.second > b.second;
}
bool cmp(pair<long long int, long long int>& a,
         pair<long long int, long long int>& b) {
  return a.second < b.second;
}
template <typename T1, typename T2>
struct less_second {
  bool operator()(pair<T1, T2> const& a, pair<T1, T2> const& b) const {
    return a.second < b.second;
  }
};
long long int baselog(long long int base, long long int x) {
  return (long long int)(log(x) / log(base));
}
vector<int> visted(101, 0);
void dfs(vector<vector<int>> v, int ind) {
  if (visted[ind]) return;
  visted[ind] = 1;
  for (long long int i = 0; i < v.size(); i++) {
    if (!visted[i] and (v[i][0] == v[ind][0] or v[i][1] == v[ind][1])) {
      dfs(v, i);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> s(n);
  vector<long long int> c(n);
  for (long long int i = 0; i < n; i++) cin >> s[i];
  for (long long int i = 0; i < n; i++) cin >> c[i];
  long long int ans = maximum;
  for (long long int j = 0; j < n; j++) {
    long long int temp1 = c[j];
    long long int temp2 = maximum;
    long long int temp3 = maximum;
    long long int mini = maximum;
    for (long long int i = 0; i < j + 1; i++) {
      if (s[i] < s[j] and c[i] < mini) {
        temp2 = c[i];
        mini = c[i];
      }
    }
    mini = maximum;
    for (long long int i = j; i < n; i++) {
      if (s[i] > s[j] and c[i] < mini) {
        temp3 = c[i];
        mini = c[i];
      }
    }
    mini = temp1 + temp2 + temp3;
    ans = min(ans, mini);
  }
  if (ans == maximum) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
