#include <bits/stdc++.h>
using namespace std;
int dxx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dp[3003][3];
int a[3003];
int c[3003];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  dp[0][0] = a[1];
  dp[1][1] = dp[1][2] = 1000000007;
  int ans = 1000000007;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = c[i];
    dp[i][1] = dp[i][2] = 1000000007;
    for (int k = i - 1; k > 0; k--) {
      if (a[i] > a[k]) {
        dp[i][1] = min(dp[i][1], c[i] + dp[k][0]);
        dp[i][2] = min(dp[i][2], c[i] + dp[k][1]);
      }
    }
    ans = min(ans, dp[i][2]);
  }
  if (ans >= 1000000007) ans = -1;
  printf("%d\n", ans);
  return 0;
}
