#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001][4], n, a[3030], c[3030];
int solve(int pos, int last, int cnt) {
  if (cnt == 3) return 0;
  if (pos > n) {
    if (cnt != 3)
      return 400000000;
    else
      return 0;
  }
  if (dp[pos][last][cnt] != -1) return dp[pos][last][cnt];
  int m1, m2;
  m1 = m2 = 400000000;
  if (a[pos] > a[last]) m1 = c[pos] + solve(pos + 1, pos, cnt + 1);
  m2 = solve(pos + 1, last, cnt);
  return dp[pos][last][cnt] = min(m1, m2);
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  memset(dp, -1, sizeof(dp));
  int ans = solve(1, 0, 0);
  if (ans >= 400000000)
    cout << "-1" << endl;
  else
    cout << ans << endl;
}
