#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  vector<long long> b(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long cntZero = 0;
  vector<long long> cnt(k);
  for (long long i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  for (long long i = 0; i < k; i++) {
    if (cnt[i] == 0) cntZero++;
  }
  set<pair<long long, long long>> s;
  for (long long i = 0; i < n; i++) {
    s.insert({b[i], i});
  }
  long long ans = 0;
  while (cntZero) {
    auto pp = *s.begin();
    s.erase(s.begin());
    if (cnt[a[pp.second]] > 1) {
      cntZero--;
      cnt[a[pp.second]]--;
      ans += pp.first;
    }
  }
  cout << ans << endl;
}
