#include <bits/stdc++.h>
using namespace std;
int a[100020];
long long b[100020];
vector<long long> v[100020], t;
int main(void) {
  int n, k;
  int i, j;
  long long o;
  set<int> s;
  scanf("%d %d", &n, &k);
  s.clear();
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s.insert(a[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &b[i]);
    v[a[i]].push_back(b[i]);
  }
  for (i = 1; i <= k; i++)
    if ((signed)v[i].size() > 1) {
      sort(v[i].begin(), v[i].end());
      for (j = 0; j + 1 < (signed)v[i].size(); j++) t.push_back(v[i].at(j));
    }
  sort(t.begin(), t.end());
  for (i = o = 0; i + (signed)s.size() < k; i++) o += t.at(i);
  printf("%I64d\n", o);
  return 0;
}
