#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
long long a[3005], b[3005], dp[3005][5];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &b[i]);
    }
    memset(dp, inf, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      dp[i][1] = b[i];
      for (int j = i + 1; j <= n; j++) {
        if (a[j] > a[i]) {
          for (int k = 2; k <= 3; k++) {
            dp[j][k] = min(dp[j][k], dp[i][k - 1] + b[j]);
          }
        }
      }
    }
    long long sum = inf;
    for (int i = 1; i <= n; i++) {
      sum = min(sum, dp[i][3]);
    }
    if (sum == inf)
      printf("-1\n");
    else
      printf("%lld\n", sum);
  }
}
