#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> Task;
unordered_map<int, int> Idle;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    int val;
    cin >> val;
    Task[val]++;
    Idle[i] = val;
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Cost;
  for (int i = 1; i <= N; i++) {
    int val;
    cin >> val;
    if (Task[Idle[i]] == 1) continue;
    Cost.push(make_pair(val, i));
  }
  long long int Ans = 0;
  for (int i = 1; i <= K; i++) {
    if (Task[i] == 0) {
      while (!Cost.empty()) {
        pair<int, int> u = Cost.top();
        Cost.pop();
        if (Task[Idle[u.second]] > 1) {
          Task[Idle[u.second]]--;
          Ans += u.first;
          Task[i]++;
          break;
        }
      }
    }
  }
  cout << Ans;
  return 0;
}
