#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  int n;
  cin >> n;
  vector<int> font(n);
  for (int i = (0); i < (n); i++) {
    cin >> font[i];
  }
  int ans = (int)1e9;
  vector<vector<int>> dp(4, vector<int>(n, (int)1e9));
  for (int i = (0); i < (n); i++) {
    int price;
    cin >> price;
    dp[1][i] = price;
    for (int j = (0); j < (i); j++) {
      if (font[j] >= font[i]) continue;
      dp[2][i] = min(dp[2][i], dp[1][j] + price);
      dp[3][i] = min(dp[3][i], dp[2][j] + price);
    }
    ans = min(ans, dp[3][i]);
  }
  if (ans > 4e8)
    cout << -1;
  else
    cout << ans;
}
