#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 1e14;
const double pi = acos(-1.0);
const double eps = 1e-6;
LL s[maxn], c[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  LL ans = 1e14;
  for (int i = 2; i < n; i++) {
    LL ans1 = 1e14, ans2 = 1e14;
    for (int j = i - 1; j >= 1; j--) {
      if (s[j] < s[i]) ans1 = min(ans1, c[j]);
    }
    for (int j = i + 1; j <= n; j++) {
      if (s[j] > s[i]) ans2 = min(ans2, c[j]);
    }
    ans = min(ans, c[i] + ans1 + ans2);
  }
  if (ans == 1e14) ans = -1;
  cout << ans;
  return 0;
}
