#include <bits/stdc++.h>
using namespace std;
int sz[3003], cst[3003], temp[3003];
bool vis[3003];
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) scanf("%d", &sz[i]);
    for (int i = 0; i < n; i++) scanf("%d", &cst[i]);
    memset(vis, 0, sizeof vis);
    for (int i = 0; i < n; i++) {
      temp[i] = 1000000009;
      for (int j = i + 1; j < n; j++)
        if (sz[i] < sz[j]) vis[i] = 1, temp[i] = min(temp[i], cst[i] + cst[j]);
    }
    int res = -1;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        if (vis[j] && sz[i] < sz[j]) {
          if (res == -1)
            res = temp[j] + cst[i];
          else
            res = min(res, temp[j] + cst[i]);
        }
    printf("%d\n", res);
  }
  return 0;
}
