#include <bits/stdc++.h>
using namespace std;
int dp[3010][3010][5];
int ind[3010], cost[3010], n;
int Dp(int i, int j, int cnt) {
  if (cnt == 3) return 0;
  if (i == n || j == n) return 1000000007;
  if (dp[i][j][cnt] != -1) return dp[i][j][cnt];
  int x = 1000000007, y = 1000000007;
  if (cnt == 0) {
    x = cost[i] + Dp(i + 1, i, cnt + 1);
    y = Dp(i + 1, i, cnt);
    return dp[i][j][cnt] = min(x, y);
  }
  if (ind[i] > ind[j]) x = cost[i] + Dp(i + 1, i, cnt + 1);
  y = Dp(i + 1, j, cnt);
  return dp[i][j][cnt] = min(x, y);
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ind[i];
  for (int i = 0; i < n; i++) cin >> cost[i];
  int res = Dp(0, 0, 0);
  if (res == 1000000007)
    printf("-1\n");
  else
    printf("%d\n", res);
  return 0;
}
