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