#include <bits/stdc++.h>
using namespace std;
long long int dp[4][5000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a[4000], n;
  int i, j, k;
  cin >> n;
  for (i = 1; i <= 3; i++)
    for (j = 1; j <= n; j++) dp[i][j] = 900000007;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> dp[1][i];
  for (i = 2; i <= 3; i++) {
    for (j = i; j <= n; j++) {
      for (k = i - 1; k < j; k++) {
        if (a[k] < a[j]) dp[i][j] = min(dp[i][j], dp[1][j] + dp[i - 1][k]);
      }
    }
  }
  long long int ans = 900000007;
  for (i = 3; i <= n; i++) ans = min(ans, dp[3][i]);
  if (ans >= 900000007)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
