#include <bits/stdc++.h>
using namespace std;
struct Edge {
  Edge(int source, int dest, int weight) : u(source), v(dest), w(weight){};
  int u, v, w;
};
struct option {
  bool operator()(const Edge& a, const Edge& b) { return a.w < b.w; }
};
int main() {
  cin.tie(NULL), cout.tie(NULL), ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> time_pursuade(n);
  vector<int> laziest_idler(k, -1);
  vector<int> job_chosen(n);
  for (int i = 0; i < n; ++i) {
    cin >> job_chosen[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> time_pursuade[i];
  }
  vector<bool> redundant(n, true);
  for (int i = 0; i < n; ++i) {
    int job = job_chosen[i] - 1;
    if (laziest_idler[job] == -1) {
      laziest_idler[job] = i;
      redundant[i] = false;
    } else if (time_pursuade[laziest_idler[job]] < time_pursuade[i]) {
      redundant[laziest_idler[job]] = true;
      laziest_idler[job] = i;
      redundant[i] = false;
    }
  }
  vector<int> res;
  int notChosen = 0;
  for (int i = 0; i < k; ++i) {
    if (laziest_idler[i] == -1) {
      notChosen++;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (redundant[i]) {
      res.push_back(time_pursuade[i]);
    }
  }
  sort(res.begin(), res.end());
  long long ans = 0;
  for (int i = 0; i < min(notChosen, (int)res.size()); ++i) {
    ans += res[i];
  }
  cout << ans;
  return 0;
}
