#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
const long long inf = 1e12;
int n, m, a[N], c[N];
long long dp[N], ans;
int main() {
  while (~scanf("%d", &n)) {
    long long ans = inf;
    for (int i = 1; i <= n; i++) {
      scanf("%d", a + i);
      dp[i] = inf;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", c + i);
      for (int j = 1; j < i; j++) {
        if (a[i] > a[j]) {
          dp[i] = min(dp[i], (long long)c[j] + c[i]);
          ans = min(ans, dp[j] + c[i]);
        }
      }
    }
    if (ans == inf) ans = -1;
    printf("%I64d\n", ans);
  }
  return 0;
}
