#include <bits/stdc++.h>
using namespace std;
int fontSize[3010], cost[3010], ans = 1e9, n, dp[3010][5];
int solve(int pos, int alturaMinima, int escolhidos) {
  if (escolhidos == 3) return 0;
  if (pos >= n) return 1e9;
  if (dp[pos][escolhidos] != -1) return dp[pos][escolhidos];
  int inclue = 1e9;
  for (int i = pos; i < n; i++) {
    if (fontSize[i] >= alturaMinima)
      inclue =
          min(inclue, solve(i + 1, fontSize[i] + 1, escolhidos + 1) + cost[i]);
  }
  return dp[pos][escolhidos] = inclue;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &fontSize[i]);
  for (int i = 0; i < n; i++) scanf("%d", &cost[i]);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) {
    ans = min(ans, solve(i + 1, fontSize[i] + 1, 1) + cost[i]);
  }
  if (ans == 1e9)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
