#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> v[100005];
  int a[100005];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int first;
    scanf("%d", &first);
    v[a[i]].push_back(first);
  }
  int cnt = 0;
  vector<int> tmp;
  for (int i = 1; i <= k; i++) {
    if (v[i].empty())
      cnt++;
    else {
      sort(v[i].begin(), v[i].end());
      for (int j = 0; j < v[i].size() - 1; j++) tmp.push_back(v[i][j]);
    }
  }
  sort(tmp.begin(), tmp.end());
  long long ans = 0;
  for (int i = 0; i < cnt; i++) ans += tmp[i];
  printf("%lld\n", ans);
}
