#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
const int INF = 0x3fffffff;
int dp[3][maxn], num[maxn], Min = INF;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 3; i++) {
    fill(dp[i], dp[i] + maxn, INF);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &dp[0][i]);
  }
  for (int i = 0; i < 3; i++) {
    for (int j = i; j < n; j++) {
      for (int k = 0; k < j; k++) {
        if (num[j] > num[k]) {
          dp[i][j] = min(dp[i][j], dp[0][j] + dp[i - 1][k]);
        }
      }
      if (i == 2 && Min > dp[i][j]) {
        Min = dp[i][j];
      }
    }
  }
  if (Min == INF)
    printf("-1\n");
  else
    printf("%d\n", Min);
  return 0;
}
