#include <bits/stdc++.h>
using namespace std;
int n, k, a[100010], p[100010], b[100010], mx[100010], pos[100010];
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]);
    if (b[i] > mx[a[i]]) {
      mx[a[i]] = b[i];
      pos[a[i]] = i;
    }
  }
  int cnt = 0, num = 0;
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    if (mx[i] == 0) cnt++;
  }
  for (int i = 1; i <= n; i++) {
    if (pos[a[i]] != i) p[++num] = b[i];
  }
  sort(p + 1, p + 1 + num);
  for (int i = 1; i <= cnt; i++) ans += p[i];
  cout << ans << endl;
  return 0;
}
