#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  sort(a.begin(), a.end());
  vector<bool> ok(n + 1, false);
  vector<int> vals;
  int remain = k;
  for (int i = n - 1; i >= 0; i--) {
    if (!ok[a[i].second]) {
      ok[a[i].second] = true;
      remain--;
    } else {
      vals.push_back(a[i].first);
    }
  }
  sort(vals.begin(), vals.end());
  long long ans = 0;
  for (int i = 0; i < remain; i++) {
    ans += vals[i];
  }
  cout << ans;
}
