#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long n) {
  if (n == 1) {
    return false;
  }
  long long i = 2;
  while (i * i <= n) {
    if (n % i == 0) {
      return false;
    }
    i += 1;
  }
  return true;
}
long long countSetBits(long long n) {
  long long count = 0;
  while (n) {
    count += n & 1;
    n >>= 1;
  }
  return count;
}
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a);
    a = (a * a);
    b = b / 2;
  }
  return ans;
}
int main() {
  long long t = 1;
  while (t--) {
    long long n, i, j, k, m, ans = 100000000000, p = 0;
    cin >> n;
    long long s[n], c[n];
    for (i = 0; i < n; i++) cin >> s[i];
    for (i = 0; i < n; i++) cin >> c[i];
    for (i = 1; i < n - 1; i++) {
      long long c1 = 100000000000, c2 = 100000000000;
      for (j = 0; j < i; j++) {
        if (s[j] < s[i]) {
          c1 = min(c1, c[j]);
        }
      }
      for (j = i + 1; j < n; j++) {
        if (s[j] > s[i]) {
          c2 = min(c2, c[j]);
        }
      }
      if (c1 != 100000000000 && c2 != 100000000000) {
        ans = min(ans, c1 + c2 + c[i]);
        p = 1;
      }
    }
    if (p == 1)
      cout << ans;
    else
      cout << "-1";
  }
}
