#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long x[n + 5], y[n + 5];
  map<long long, long long> mp;
  vector<pair<long long, long long>> z;
  set<long long> w;
  for (long long i = 0; i < n; i++) {
    cin >> x[i];
    mp[x[i]]++;
    w.insert(x[i]);
  }
  long long l = m - w.size();
  for (long long i = 0; i < n; i++) {
    cin >> y[i];
  }
  for (long long i = 0; i < n; i++) {
    z.push_back(make_pair(y[i], x[i]));
  }
  sort(z.begin(), z.end());
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (l > 0) {
      if (mp[z[i].second] > 1) {
        sum += z[i].first;
        mp[z[i].second]--;
        l--;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
