#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    vector<int> s(n), c(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    vector<vector<int> > dp(n, vector<int>(3, INT_MAX));
    dp[n - 1][0] = c[n - 1];
    dp[n - 2][0] = c[n - 2];
    if (s[n - 2] < s[n - 1]) dp[n - 2][1] = c[n - 2] + c[n - 1];
    int ans = INT_MAX;
    for (int i = n - 3; i >= 0; i--) {
      dp[i][0] = c[i];
      for (int j = i + 1; j < n; j++) {
        if (s[j] > s[i]) {
          dp[i][1] = min(dp[i][1], c[i] + c[j]);
          if (dp[j][1] != INT_MAX) dp[i][2] = min(dp[i][2], c[i] + dp[j][1]);
        }
      }
      ans = min(ans, dp[i][2]);
    }
    cout << (ans == INT_MAX ? -1 : ans) << endl;
  }
}
