#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n;
int s[3005];
int c[3005];
int dp[3005];
int main() {
  memset(dp, INF, sizeof(dp));
  cin >> n;
  int ans = INF;
  for (int i = (1); i <= (n); i++) cin >> s[i];
  for (int i = (1); i <= (n); i++) cin >> c[i];
  for (int i = (1); i <= (n); i++) {
    for (int j = (i + 1); j <= (n); j++) {
      if (s[j] > s[i]) dp[i] = min(dp[i], c[j]);
    }
  }
  for (int i = (1); i <= (n); i++) {
    for (int j = (i + 1); j <= (n); j++) {
      if (s[j] > s[i] && dp[i] != INF) {
        ans = min(ans, c[i] + c[j] + dp[j]);
      }
    }
  }
  if (ans == INF)
    puts("-1");
  else
    cout << ans << endl;
}
