#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
priority_queue<int> q;
vector<int> s[maxn];
int a[maxn], b[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  long long ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) s[a[i]].push_back(b[i]);
  int t = 0;
  for (int i = 1; i <= k; i++) {
    if (!s[i].size()) {
      t++;
      continue;
    }
    sort(s[i].begin(), s[i].end());
    for (int j = 0; j < s[i].size() - 1; j++) q.push(-s[i][j]);
  }
  while (t--) {
    ans -= q.top();
    q.pop();
  }
  cout << ans << endl;
  return 0;
}
