#include <bits/stdc++.h>
using namespace std;
int s[1 << 20], val[1 << 20], n, res = INT_MAX, dp1[1 << 20], dp2[1 << 20];
map<int, int> scale;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) cin >> val[i], dp1[i] = INT_MAX;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (s[i] < s[j]) dp1[j] = min(dp1[j], val[i] + val[j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (s[i] < s[j] && dp1[i] != INT_MAX) {
        res = min(res, dp1[i] + val[j]);
      }
    }
  }
  if (res == INT_MAX)
    cout << -1;
  else
    cout << res;
}
