#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[n];
  map<long long, long long> mp;
  set<long long> s;
  for (auto i = 0; i < n; ++i) {
    cin >> a[i];
    mp[a[i]]++;
    s.insert(a[i]);
  }
  long long b[n];
  vector<pair<long long, long long>> pii;
  for (auto i = 0; i < n; ++i) {
    cin >> b[i];
    pii.push_back(make_pair(b[i], a[i]));
  }
  sort(pii.begin(), pii.end());
  long long to_persuade = k - s.size();
  long long count = 0;
  long long cost = 0;
  for (auto i = 0; i < n && count != to_persuade; ++i) {
    if (mp[pii[i].second] > 1) {
      cost += pii[i].first;
      mp[pii[i].second]--;
      count++;
    }
  }
  cout << cost;
  return 0;
}
