#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0), b(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<int> jobs(n + 1, -1);
  vector<int> temp;
  int left_jobs = k;
  for (int i = 0; i < n; i++) {
    auto target_idx = a[i];
    if (jobs[target_idx] == -1) {
      jobs[target_idx] = i;
      left_jobs--;
    } else {
      auto prev_idler = jobs[target_idx];
      if (b[prev_idler] <= b[i]) {
        jobs[target_idx] = i;
        temp.push_back(b[prev_idler]);
      } else {
        temp.push_back(b[i]);
      }
    }
  }
  sort(temp.begin(), temp.end());
  unsigned long long ret = 0;
  for (int i = 0; i < left_jobs; i++) ret += temp[i];
  cout << ret << '\n';
  return 0;
}
