import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;
import std.bigint;
import core.checkedint;

void main()
{
	int n = readln.chomp.to!int;
	long[] s = readln.chomp.split.map!(to!long).array;
	int[] c = readln.chomp.split.map!(to!int).array;
	long[] sub = new long[](n);
	foreach (i; 0..n) {
		int v = int.max;
		foreach (j; i + 1 .. n) {
			if (s[i] >= s[j]) {
				continue;
			}
			v = min(v, c[j]);
		}
		sub[i] = v;
	}
	long ans = int.max;
	foreach (i; 0..n) {
		foreach (j; i + 1 .. n) {
			if (s[i] >= s[j]) {
				continue;
			}
			debug verbose(i, j, sub[j], c[i] + c[j] + sub[j]);
			ans = min(ans, c[i] + c[j] + sub[j]);
		}
	}
	if (ans >= int.max) {
		writeln = -1;
	} else {
		ans.writeln;
	}
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

