#include <bits/stdc++.h>
using namespace std;
int main() {
  int m;
  cin >> m;
  int a[m][2], sum = 0;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[j][i];
    }
  }
  int ans = 1e9 + 7;
  for (int i = 0; i < m; i++) {
    int b = -1;
    int cost = a[i][1];
    for (int j = 0; j < i; j++) {
      if (a[j][0] >= a[i][0]) continue;
      if (b == -1 || a[b][1] > a[j][1]) {
        b = j;
      }
    }
    if (b == -1) {
      continue;
    }
    cost = cost + a[b][1];
    b = -1;
    for (int k = i + 1; k < m; k++) {
      if (a[k][0] <= a[i][0]) continue;
      if (b == -1 || a[b][1] > a[k][1]) {
        b = k;
      }
    }
    if (b == -1) {
      continue;
    }
    cost = cost + a[b][1];
    ans = min(ans, cost);
  }
  if (ans == 1e9 + 7) {
    cout << "-1";
  } else {
    cout << ans;
  }
}
