#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, ans;
  cin >> n;
  long long a[3003], cost[3003], dp[4][3003];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> cost[i];
    dp[1][i] = cost[i];
    dp[2][i] = dp[3][i] = 1000000000000000ll;
  }
  ans = 1000000000000000ll;
  for (i = 1; i < n; i++) {
    for (j = 0; j < i; j++) {
      dp[1][i] = cost[i];
      if (a[i] > a[j]) {
        dp[2][i] = min(dp[2][i], dp[1][j] + cost[i]);
        dp[3][i] = min(dp[3][i], dp[2][j] + cost[i]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    ans = min(ans, dp[3][i]);
  }
  if (ans == 1000000000000000ll)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
