#include <bits/stdc++.h>
#pragma warning(disable : 4996);
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3e3 + 10;
int n;
int s[N], c[N];
int ans;
int res;
int dp[N];
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", s + i);
    for (int i = 1; i <= n; i++) scanf("%d", c + i);
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 1; i < n; i++)
      for (int j = i + 1; j <= n; j++) {
        if (s[i] < s[j]) dp[i] = min(dp[i], c[j]);
      }
    ans = inf;
    for (int i = 1; i < n; i++) {
      res = inf;
      for (int j = i + 1; j < n; j++) {
        if (s[j] > s[i]) {
          res = min(res, c[j] + dp[j]);
        }
      }
      ans = min(ans, res + c[i]);
    }
    if (ans < inf)
      printf("%d\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
