#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<int, int>> ba(n);
  unordered_map<int, vector<int>> job_list;
  for (ll i = 0; i < n; i++) {
    cin >> ba[i].second;
  }
  for (ll i = 0; i < n; i++) {
    cin >> ba[i].first;
  }
  for (ll i = 0; i < n; i++) {
    ll b = ba[i].first;
    ll a = ba[i].second;
    job_list[a].push_back(b);
  }
  vector<int> cand_time;
  ll task_done = 0;
  for (auto el : job_list) {
    task_done++;
    ll k = el.first;
    vector<int> v = el.second;
    if (v.size() <= 1) continue;
    sort(v.begin(), v.end());
    for (ll i = 0; i < v.size() - 1; i++) {
      cand_time.push_back(v[i]);
    }
  }
  ll remain_task = k - task_done;
  sort(cand_time.begin(), cand_time.end());
  ll ans = 0;
  for (ll i = 0; i < remain_task; i++) {
    ans += cand_time[i];
  }
  cout << ans << "\n";
  return 0;
}
