#include <bits/stdc++.h>
using namespace std;
int n, k;
long long ans;
int a[100002];
int b[100002];
bool jobs[100002];
priority_queue<int> pq[100002];
priority_queue<int> pq2;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) {
    pq[a[i]].push(-b[i]);
    jobs[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    while (pq[i].size() > 1) {
      pq2.push(pq[i].top());
      pq[i].pop();
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!jobs[i]) {
      ans -= pq2.top();
      pq2.pop();
    }
  }
  cout << ans << endl;
}
