#include <bits/stdc++.h>
using namespace std;
void print_array(int qntd_of_jobs[], int k_jobs) {
  int job;
  for (job = 1; job <= k_jobs; job++)
    printf("job: %d && amount: %d\n", job, qntd_of_jobs[job]);
  printf("\n");
}
void print_pair(pair<long long, int> P[], int n_people) {
  int person;
  for (person = 1; person <= n_people; person++)
    printf("(%lli, %d) ", P[person].first, P[person].second);
  printf("\n\n");
}
int main() {
  int n_people, k_jobs, qntd_of_jobs[100100], person, job,
      qntd_of_available_jobs, time_i;
  long long total_time = 0;
  set<int> unique_jobs;
  pair<long long, int> pair_time_job[100100];
  cin >> n_people >> k_jobs;
  memset(qntd_of_jobs, 0, sizeof(qntd_of_jobs));
  for (person = 1; person <= n_people; person++) {
    cin >> job;
    qntd_of_jobs[job]++;
    unique_jobs.insert(job);
    pair_time_job[person].second = job;
  }
  for (person = 1; person <= n_people; person++)
    cin >> pair_time_job[person].first;
  qntd_of_available_jobs = k_jobs - int(unique_jobs.size());
  sort(pair_time_job, pair_time_job + n_people + 1);
  for (time_i = 1; time_i <= n_people; time_i++) {
    if (!qntd_of_available_jobs) break;
    if (qntd_of_jobs[pair_time_job[time_i].second] > 1) {
      total_time += pair_time_job[time_i].first;
      qntd_of_available_jobs--;
      qntd_of_jobs[pair_time_job[time_i].second]--;
    }
  }
  cout << total_time << endl;
  return 0;
}
