#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, takenJob = 0;
  long long persuadeTime = 0;
  cin >> n >> k;
  vector<int> jobs(k + 1, -1);
  vector<pair<long long, int>> idlers(n);
  for (int i = 0; i < n; i++) cin >> idlers[i].second;
  for (int i = 0; i < n; i++) cin >> idlers[i].first;
  sort(idlers.begin(), idlers.end());
  for (int i = n - 1; i >= 0; i--) {
    if (jobs[idlers[i].second] == -1) {
      jobs[idlers[i].second] = i;
      takenJob++;
    }
  }
  for (int i = 0; takenJob < k && i < n; i++) {
    if (jobs[idlers[i].second] == i) continue;
    persuadeTime += idlers[i].first;
    takenJob++;
  }
  cout << persuadeTime << endl;
  return 0;
}
