#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base);
    base = (base * base);
    exp /= 2;
  }
  return res;
}
long long mod(long long a, long long b) { return (a % b + b) % b; }
long long powerm(long long base, long long exp, long long mod) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long dp[3005][3005][3];
long long solve(long long s[], long long c[], long long n, long long idx,
                long long prev_idx, long long k) {
  if (k == 3) {
    return 0;
  }
  if (idx == n + 1) {
    return 1e15;
  }
  if (prev_idx != -1) {
    if (dp[idx][prev_idx][k] != -1) return dp[idx][prev_idx][k];
    long long ans = 1e15;
    if (s[prev_idx] < s[idx])
      ans = min(ans, c[idx] + solve(s, c, n, idx + 1, idx, k + 1));
    ans = min(ans, solve(s, c, n, idx + 1, prev_idx, k));
    return dp[idx][prev_idx][k] = ans;
  } else {
    long long ans = 1e15;
    ans = min(ans, c[idx] + solve(s, c, n, idx + 1, idx, k + 1));
    ans = min(ans, solve(s, c, n, idx + 1, prev_idx, k));
    return ans;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long s[n], c[n];
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < n; i++) cin >> c[i];
  long long prev_idx = -1, idx = 0;
  memset(dp, -1, sizeof(dp));
  long long ans = solve(s, c, n, idx, prev_idx, 0);
  if (ans == 1e15)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}
