#include <bits/stdc++.h>
using namespace std;
priority_queue<int> pq[100005];
int ar[100005];
int br[100005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &br[i]);
    pq[ar[i]].push(-br[i]);
  }
  long long int ans = 0;
  priority_queue<int> kill;
  for (int i = 1; i <= m; i++) {
    while (pq[i].size() > 1) {
      kill.push(pq[i].top());
      pq[i].pop();
    }
  }
  for (int i = 1; i <= m; i++) {
    if (pq[i].size() == 0) {
      ans -= kill.top();
      kill.pop();
    }
  }
  printf("%lld\n", ans);
  return 0;
}
