#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct People {
  int xz, time;
} a[maxn];
int c[maxn];
bool cmp(People a, People b) { return a.time < b.time; }
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].xz);
    c[a[i].xz]++;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].time);
  sort(a + 1, a + 1 + n, cmp);
  int cnt = 0;
  long long ans = 0;
  for (int i = 1; i <= k; i++)
    if (!c[i]) cnt++;
  for (int i = 1; i <= n && cnt; i++) {
    if (c[a[i].xz] > 1) {
      c[a[i].xz]--;
      ans += a[i].time, cnt--;
    }
  }
  printf("%lld\n", ans);
}
