#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
template <class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
const int LM = 1e5;
long long n, k, c, a[LM + 1], b[LM + 1], s;
vector<long long> v[LM + 1];
vector<long long> ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    v[a[i]].push_back(b[i]);
  }
  for (int i = 1; i <= k; i++) {
    sort(v[i].begin(), v[i].end());
    if (!v[i].empty()) {
      v[i].pop_back();
      c++;
    }
    for (auto u : v[i]) {
      ans.push_back(u);
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i <= k - c - 1; i++) s += ans[i];
  cout << s << endl;
  return 0;
}
