#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32100000")
#pragma GCC optimize("O3")
using namespace std;
int n, k;
map<int, vector<int>> jobs;
int a[200005];
int b[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  cout.precision(9);
  srand(time(0));
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    --a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    jobs[a[i]].push_back(b[i]);
  }
  vector<int> can;
  for (auto &i : jobs) {
    sort(i.second.begin(), i.second.end());
    for (int j = 0; j < i.second.size() - 1; j++) {
      can.push_back(i.second[j]);
    }
  }
  long long ans = 0LL;
  sort(can.rbegin(), can.rend());
  for (int i = 0; i < k; i++) {
    if (!jobs.count(i)) {
      ans += can.back();
      can.pop_back();
    }
  }
  cout << ans;
  return 0;
}
