#include <bits/stdc++.h>
using namespace std;
long long int s[3001], c[3001];
int main() {
  long long int n, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> c[i];
  }
  long long int x1, x2;
  long long int ans = INT_MAX;
  for (i = 2; i <= n - 1; i++) {
    x1 = INT_MAX;
    x2 = INT_MAX;
    for (j = 1; j < i; j++) {
      if (s[j] < s[i]) {
        x1 = min(x1, c[j]);
      }
    }
    for (j = i + 1; j <= n; j++) {
      if (s[j] > s[i]) {
        x2 = min(x2, c[j]);
      }
    }
    ans = min(ans, c[i] + x1 + x2);
  }
  (ans < INT_MAX) ? cout << ans : cout << -1;
  return 0;
}
