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