#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, s[3000 + 5], c[3000 + 5], f[3000 + 5][5];
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int main() {
  n = read();
  memset(f, inf, sizeof(f));
  for (int i = 1; i <= n; i++) s[i] = read();
  for (int i = 1; i <= n; i++) c[i] = read();
  for (int i = 1; i <= n; i++) {
    f[i][1] = c[i];
    for (int j = 1; j < i; j++)
      if (s[j] < s[i]) f[i][2] = min(f[j][1] + c[i], f[i][2]);
    for (int j = 1; j < i; j++)
      if (s[j] < s[i]) f[i][3] = min(f[j][2] + c[i], f[i][3]);
  }
  int ans = inf;
  for (int i = 1; i <= n; i++)
    if (f[i][3]) ans = min(ans, f[i][3]);
  if (ans == inf)
    cout << -1;
  else
    cout << ans;
  return 0;
}
