#include <bits/stdc++.h>
using namespace std;
const int M = 3111;
int dp[M];
long long s[M], c[M], ans = 1e18;
int32_t main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  s[n] = 1e18, c[n] = 1e18;
  dp[0] = n;
  dp[1] = (s[0] < s[1] ? 0 : n);
  for (int i = 2; i < n; i++) {
    long long t = 1e18, a = 1e18;
    for (int j = i - 1; j > 0; j--) {
      if (s[i] <= s[j]) continue;
      if (c[j] < t) t = c[j], dp[i] = j;
      a = min(a, c[i] + c[j] + c[dp[j]]);
    }
    if (t == 1e18) continue;
    ans = min(ans, a);
    if (s[0] < s[dp[i]]) ans = min(ans, c[i] + c[dp[i]] + c[0]);
  }
  cout << (ans == 1e18 ? -1 : ans);
  return 0;
}
