#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[3003], c[3003], dp1[3003] = {0}, dp2[3003] = {0};
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (a[i] > a[j]) {
        if (dp1[i] != 0)
          dp1[i] = min(dp1[i], c[i] + c[j]);
        else
          dp1[i] = c[i] + c[j];
      }
    }
  }
  for (int i = 2; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (a[i] > a[j]) {
        if (dp2[i] != 0 && dp1[j] != 0)
          dp2[i] = min(dp2[i], dp1[j] + c[i]);
        else if (dp2[i] == 0 && dp1[j] != 0)
          dp2[i] = dp1[j] + c[i];
      }
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++)
    if (dp2[i] != 0) ans = min(ans, dp2[i]);
  if (ans != INT_MAX)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
