#include <bits/stdc++.h>
using namespace std;
int n, m[3005][2], an;
long long ans = -1;
pair<long long, long long> a[3005];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    m[i][0] = -1;
    m[i][1] = -1;
    cin >> a[i].first;
  }
  for (int i = 0; i < n; i++) cin >> a[i].second;
  for (int i = n - 1; i >= 0; i--) {
    int m1 = -1, m2 = -1;
    for (int j = i + 1; j < n; j++) {
      if (a[j].first > a[i].first && (m1 == -1 || m1 > a[j].second)) {
        m1 = a[j].second;
        m[i][0] = j;
      }
      if (m[j][0] != -1 && a[j].first > a[i].first &&
          (m2 == -1 || m2 > a[j].second + a[m[j][0]].second)) {
        m2 = a[j].second + a[m[j][0]].second;
        m[i][1] = j;
      }
    }
  }
  for (int i = 0; i < n; i++)
    if (m[i][1] != -1 && (ans == -1 || ans > a[i].second + a[m[i][1]].second +
                                                 a[m[m[i][1]][0]].second))
      ans = a[i].second + a[m[i][1]].second + a[m[m[i][1]][0]].second;
  cout << ans << endl;
  return 0;
}
