#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<pair<long long, long long> > v;
long long a[100001], b[100001];
bool kt[100001];
map<long long, int> d;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) v.push_back(make_pair(b[i], a[i]));
  v.push_back(make_pair(0, 0));
  sort(v.begin(), v.end());
  long long dem = 0;
  for (int i = 0; i < v.size(); i++) {
    if (d[v[i].second] == 0)
      d[v[i].second] = i;
    else {
      kt[d[v[i].second]] = true;
      d[v[i].second] = i;
    }
    kt[i] = false;
  }
  dem = k - d.size() + 1;
  long long s = 0;
  for (int i = 0; i < v.size(); i++) {
    if (dem == 0) break;
    if (kt[i] == true) {
      dem--;
      s += v[i].first;
    }
  }
  cout << s;
  return 0;
}
