#include <bits/stdc++.h>
using namespace std;
struct display {
  int s, c;
};
int main(void) {
  int n;
  cin >> n;
  vector<display> d(n);
  for (int i = 0; i < n; i++) cin >> d[i].s;
  for (int i = 0; i < n; i++) cin >> d[i].c;
  const int INF = 3e8 + 1;
  int cm = INF;
  for (int j = 1; j < n - 1; j++) {
    int c_im = INF;
    for (int i = 0; i < j; i++)
      if (d[i].s < d[j].s && d[i].c < c_im) c_im = d[i].c;
    int c_km = INF;
    for (int k = j + 1; k < n; k++)
      if (d[k].s > d[j].s && d[k].c < c_km) c_km = d[k].c;
    int c = c_im + d[j].c + c_km;
    if (c < cm) cm = c;
  }
  if (cm != INF)
    cout << cm;
  else
    cout << -1;
  return 0;
}
