#include <bits/stdc++.h>
using namespace std;
long long s[3000 + 5];
long long c[3000 + 5];
long long res = 10000000000;
long long min1 = 10000000000;
long long min2 = 10000000000;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    min1 = 10000000000;
    min2 = 10000000000;
    for (int j = 1; j < i; j++) {
      if (s[j] < s[i]) {
        min1 = min(min1, c[j]);
      }
    }
    for (int j = i + 1; j <= n; j++) {
      if (s[j] > s[i]) {
        min2 = min(min2, c[j]);
      }
    }
    res = min(res, c[i] + min1 + min2);
  }
  if (res >= 10000000000)
    cout << "-1" << endl;
  else
    cout << res << endl;
  return 0;
}
