#include <bits/stdc++.h>
using namespace std;
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  init();
  long long int res = 0ll;
  int N, K, i, done = 0;
  cin >> N >> K;
  vector<pair<int, int> > arr(N);
  vector<bool> taken(N, false);
  vector<bool> job(K + 1, false);
  for (i = 0; i < N; i++) cin >> arr[i].second;
  for (i = 0; i < N; i++) cin >> arr[i].first;
  sort(arr.begin(), arr.end());
  for (i = N - 1; i >= 0; i--)
    if (job[arr[i].second] == false)
      job[arr[i].second] = true, done++, taken[i] = true;
  for (i = 0; i < N && done < K; i++)
    if (taken[i] == false) res += (long long int)arr[i].first, done++;
  cout << res;
  return 0;
}
