#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  vector<pair<int, int>> m(k);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    m[a[i] - 1] = max(m[a[i] - 1], {b[i], i});
  }
  vector<int> kek;
  for (int i = 0; i < n; ++i) {
    if (m[a[i] - 1].second != i) {
      kek.push_back(b[i]);
    }
  }
  sort(kek.begin(), kek.end());
  cout << accumulate(kek.begin(), kek.begin() + k - (n - kek.size()), 0ll);
  return 0;
}
