#include <bits/stdc++.h>
using namespace std;
vector<int> darmo;
vector<pair<int, int> > tab;
vector<bool> done;
vector<int> wolne;
int n, k;
int main() {
  scanf("%d %d", &n, &k);
  darmo.resize(n);
  tab.resize(n);
  done.resize(k + 1, false);
  long long res = 0;
  for (int i = 0; i < n; i++) scanf("%d", &darmo[i]);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tab[i].first);
    tab[i].second = i;
  }
  sort(tab.begin(), tab.end());
  reverse(tab.begin(), tab.end());
  for (int i = 0; i < n; i++) {
    if (!done[darmo[tab[i].second]]) {
      done[darmo[tab[i].second]] = true;
    } else
      wolne.push_back(tab[i].first);
  }
  sort(wolne.begin(), wolne.end());
  int x = 0;
  for (int i = 1; i < k + 1; i++)
    if (!done[i]) {
      res += (long long)wolne[x];
      x++;
    }
  printf("%lld\n", res);
  return 0;
}
