#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 2000000000
int a[3010];
int c[3010];
int num[3010];
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
for(int i = 1;i <= n; ++i) cin >> a[i];
for(int j = 1;j <= n; ++j) cin >> c[j];
int mx = MAX;
fill(num,num+3010,MAX);
for(int i = 1;i <= n; ++i){
for(int j = i+1;j <= n; ++j){
if(a[i] < a[j]){
num[j] = min(num[j],c[i]+c[j]);
}
}
}
int ans = MAX;
for(int i = 1;i <= n; ++i){
for(int j = i+1;j <= n; ++j){
if(a[i] < a[j]){
ans = min(ans,num[i]+c[j]);
}
}
}
if(ans == MAX) ans = -1;
cout << ans << endl;
return 0;
}