#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
inline long long MAX(long long a, long long b) { return (a > b) ? (a) : (b); }
inline long long MIN(long long a, long long b) { return (a < b) ? (a) : (b); }
int main() {
  int const sz = 4e3 + 10;
  long long i, j, n, a[sz + 1], b[sz + 1], k;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  long long prev[sz + 1], forw[sz + 1];
  for (i = 0; i <= n + 1; i++) {
    prev[i] = 1e18;
    forw[i] = 1e18;
  }
  for (j = 2; j <= n; j++)
    for (i = 1; i <= j - 1; i++)
      if (a[i] < a[j]) prev[j] = MIN(prev[j], b[i]);
  for (j = 1; j <= n - 1; j++)
    for (i = j + 1; i <= n; i++)
      if (a[i] > a[j]) forw[j] = MIN(forw[j], b[i]);
  long long ans = 1e18;
  for (j = 2; j <= n - 1; j++) ans = MIN(ans, b[j] + prev[j] + forw[j]);
  if (ans == 1e18)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
