#include <bits/stdc++.h>
int n, k;
int a[110000];
int b[110000];
int cost[110000];
int id[110000];
int sort_array[110000];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (int i = 1; i <= n; i++) std::cin >> a[i];
  for (int i = 1; i <= n; i++) {
    std::cin >> b[i];
    id[i] = 0;
    cost[i] = -2000000000;
  }
  for (int i = 1; i <= n; i++) {
    int job = a[i];
    if (b[i] > cost[job]) {
      cost[job] = b[i];
      id[job] = i;
    }
  }
  int need = 0;
  for (int i = 1; i <= k; i++)
    if (id[i] == 0)
      need++;
    else
      a[id[i]] = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] != 0) sort_array[++sort_array[0]] = b[i];
  std::sort(sort_array + 1, sort_array + 1 + sort_array[0]);
  long long ans = 0;
  for (int i = 0; i < need; i++) ans += sort_array[i + 1];
  std::cout << ans << std::endl;
}
