#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int n, k, a[MAX_N], b[MAX_N];
vector<int> times[MAX_N];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) {
    scanf("%d", b + i);
    times[a[i]].push_back(b[i]);
  }
  vector<int> cake;
  int empty = 0;
  for (int i = 1; i <= k; i++) {
    if (times[i].empty()) {
      empty++;
      continue;
    }
    sort(times[i].begin(), times[i].end());
    times[i].pop_back();
    for (int x : times[i]) cake.push_back(x);
  }
  sort(cake.begin(), cake.end());
  long long ans = 0;
  for (int i = 0; i < empty; i++) ans += cake[i];
  printf("%lld\n", ans);
  return 0;
}
