#include <bits/stdc++.h>
using namespace std;
map<int, int> M;
int st[3002 + 1][3002 + 1];
int dr[3002 + 1][3002 + 1];
int cost[3002 + 1];
int val[3002 + 1];
int x[3002 + 1];
int N, K;
int main() {
  int i, j, res = 300000001;
  scanf("%d", &N);
  for (i = 1; i <= N; ++i) scanf("%d", &val[i]);
  for (i = 1; i <= N; ++i) scanf("%d", &cost[i]);
  for (i = 1; i <= N; ++i) x[i] = val[i];
  sort(val + 1, val + N + 1);
  for (i = 1; i <= N; ++i)
    if (!M[val[i]]) M[val[i]] = ++K;
  for (i = 1; i <= N; ++i) x[i] = M[x[i]];
  for (i = 0; i <= N + 1; ++i)
    for (j = 0; j <= N + 1; ++j) st[i][j] = dr[i][j] = 300000001;
  for (i = 1; i <= N; ++i) {
    for (j = 1; j <= K; ++j) st[i][j] = min(st[i][j], st[i - 1][j]);
    for (j = x[i]; j <= K; ++j) st[i][j] = min(st[i][j], cost[i]);
  }
  for (i = N; i >= 1; --i) {
    for (j = 1; j <= K; ++j) dr[i][j] = min(dr[i][j], dr[i + 1][j]);
    for (j = x[i]; j >= 1; --j) dr[i][j] = min(dr[i][j], cost[i]);
  }
  for (i = 2; i < N; ++i)
    res = min(res, cost[i] + st[i - 1][x[i] - 1] + dr[i + 1][x[i] + 1]);
  if (res == 300000001)
    printf("-1\n");
  else
    printf("%d\n", res);
  return 0;
}
