#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> a[100010];
long long int b[100010];
long long int d[100010];
vector<long long int> pool;
long long int diff;
int main() {
  int n, k;
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  ;
  cin >> n >> k;
  diff = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
    if (d[a[i].second] == 0) {
      diff++;
    }
    d[a[i].second]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (d[a[i].second] > 1) {
      pool.push_back(a[i].first);
    }
    d[a[i].second]--;
  }
  long long int sum = 0;
  for (int i = 0; i < k - diff; i++) {
    sum += pool[i];
  }
  cout << sum << '\n';
}
