#include <bits/stdc++.h>
int f[3072], c[3072];
int main() {
  int n, i, j, min, sf, bf;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &f[i]);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &c[i]);
  }
  min = -1;
  for (i = 0; i < n; i++) {
    bf = 100001000;
    sf = 100001000;
    for (j = 0; j < i; j++) {
      if (f[j] < f[i] && sf > c[j]) sf = c[j];
    }
    for (j = i + 1; j < n; j++) {
      if (f[j] > f[i] && bf > c[j]) bf = c[j];
    }
    if (sf == 100001000 || bf == 100001000) continue;
    if (min == -1 || min > sf + bf + c[i]) min = sf + bf + c[i];
  }
  printf("%d\n", min);
  return 0;
}
