#include <bits/stdc++.h>
using namespace std;
int main() {
  long long x, n, k;
  cin >> n >> k;
  map<long long, vector<long long> > mp;
  vector<long long> v, s;
  long long time[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> x;
    mp[x].push_back(i);
  }
  for (long long i = 1; i <= n; i++) cin >> time[i];
  k = k - mp.size();
  map<long long, vector<long long> >::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    v = it->second;
    x = v.size();
    if (x > 1) {
      long long t = 0;
      for (long long i = 0; i < x; i++) {
        if (time[v[i]] > t) t = time[v[i]];
      }
      bool con = true;
      for (long long i = 0; i < x; i++) {
        if (time[v[i]] == t && con)
          con = 0;
        else
          s.push_back(time[v[i]]);
      }
    }
  }
  long long sum = 0;
  sort(s.begin(), s.end());
  for (long long i = 0; i < k && i < s.size(); i++) sum += s[i];
  cout << sum << endl;
}
