#include <bits/stdc++.h>
int a, i, j, b, o, ch[123456];
struct A {
  int x, y;
} data[123456];
bool cmp(A aa, A bb) { return aa.y < bb.y; }
long long ans;
int main() {
  scanf("%d%d", &a, &b);
  for (i = 0; i < a; i++) scanf("%d", &data[i].x);
  for (i = 0; i < a; i++) scanf("%d", &data[i].y);
  std::sort(data, data + a, cmp);
  for (i = 0; i < a; i++) ch[data[i].x]++;
  o = 1;
  while (ch[o]) o++;
  for (i = 0; i < a; i++) {
    if (o > b) break;
    if (ch[data[i].x] > 1) {
      ch[data[i].x]--;
      ans += data[i].y;
      ch[o] = 1;
      while (ch[o]) o++;
    }
  }
  printf("%lld", ans);
}
