#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> job(n);
  vector<vector<int> > pp(k);
  for (int i = 0; i < n; i++) {
    cin >> job[i];
    job[i]--;
  }
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    in;
    pp[job[i]].push_back(in);
  }
  vector<int> extra;
  int need = 0;
  for (vector<int> v : pp) {
    if (v.size() > 1) {
      sort(v.begin(), v.end());
      for (int i = 0; i < v.size() - 1; i++) {
        extra.push_back(v[i]);
      }
    }
    if (v.size() == 0) need++;
  }
  sort(extra.begin(), extra.end());
  long long re = 0;
  for (int i = 0; i < need; i++) {
    re += extra[i];
  }
  cout << re << endl;
}
