#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
struct idlers {
  int jobs, time;
} a[maxn];
bool cmp(idlers a, idlers b) { return a.time < b.time; }
int book[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].jobs;
    book[a[i].jobs]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].time;
  }
  sort(a, a + n, cmp);
  int cnt = 0;
  long long ans = 0;
  for (int j = 1; j <= k; j++) {
    if (!book[j]) cnt++;
  }
  for (int i = 0; i < n && cnt; i++) {
    if (book[a[i].jobs] > 1) {
      book[a[i].jobs]--;
      ans += a[i].time;
      cnt--;
    }
  }
  cout << ans << endl;
  return 0;
}
