#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first;
  }
  for (int i = 0; i < n; ++i) {
    cin >> v[i].second;
  }
  sort(v.begin(), v.end());
  ans = v[0].second;
  for (int i = 0; i < n; ++i) {
    if (v[i].first == 1) {
      ans += v[i].second;
      break;
    }
  }
  cout << ans << endl;
}
