#include <bits/stdc++.h>
using namespace std;
int n;
long long s[10000] = {0};
long long c[10000] = {0};
long long dp[2][10000] = {0};
int main() {
  for (int i = 0; i < 10000; i++) {
    dp[0][i] = 100000000000000;
    dp[1][i] = 100000000000000;
  }
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) {
        dp[0][i] = min(dp[0][i], c[i] + c[j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (s[j] < s[i]) {
        dp[1][i] = min(dp[1][i], dp[0][j] + c[i]);
      }
    }
  }
  long long ans = 100000000000000;
  for (int i = 0; i < n; i++) {
    ans = min(ans, dp[1][i]);
  }
  if (ans == 100000000000000) ans = -1;
  cout << ans << endl;
  return 0;
}
