#include <bits/stdc++.h>
using namespace std;
int t, wq1[3003], wq2[3003], st[3003][5];
int dmc(int g, int nt) {
  if (nt == 3) return 0;
  if (g == t) return 1e9;
  if (st[g][nt] != -1e9) return st[g][nt];
  int h, re = 1e9;
  for (h = g + 1; h < t; h++)
    if (wq1[h] > wq1[g]) {
      re = min(re, wq2[h] + dmc(h, nt + 1));
    }
  return st[g][nt] = re;
}
int main() {
  int g, h, re = 1e9;
  scanf("%d", &t);
  for (g = 0; g < t; g++) scanf("%d", &wq1[g]);
  for (g = 0; g < t; g++) scanf("%d", &wq2[g]);
  for (g = 0; g < t; g++)
    for (h = 0; h < 3; h++) st[g][h] = -1e9;
  for (g = 0; g < t; g++) re = min(re, wq2[g] + dmc(g, 1));
  printf("%d\n", re == 1e9 ? -1 : re);
  return 0;
}
