#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int n;
int s[N];
int c[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  int res = (int)2e9;
  for (int i = 2; i < n; i++) {
    int x = (int)1e9, y = (int)1e9;
    for (int j = 1; j < i; j++) {
      if (s[j] < s[i]) {
        x = min(x, c[j]);
      }
    }
    for (int j = i + 1; j <= n; j++) {
      if (s[i] < s[j]) {
        y = min(y, c[j]);
      }
    }
    if (x >= (int)1e9 || y >= (int)1e9) continue;
    res = min(res, c[i] + x + y);
  }
  if (res >= (int)1e9) {
    cout << -1;
  } else {
    cout << res;
  }
  return 0;
}
