#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> arr[100003];
void read() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> arr[i].first;
  for (int i = 1; i <= n; i++) cin >> arr[i].second;
}
vector<int> jobs[100003];
void solve() {
  vector<int> possible;
  for (int i = 1; i <= n; i++) jobs[arr[i].first].push_back(arr[i].second);
  int cnt = 0;
  for (int i = 1; i <= k; i++) {
    if (jobs[i].empty()) {
      cnt++;
      continue;
    }
    sort(jobs[i].begin(), jobs[i].end());
    for (int j = 0; j < jobs[i].size() - 1; j++) possible.push_back(jobs[i][j]);
  }
  sort(possible.begin(), possible.end());
  long long ans = 0;
  for (int i = 0; i < cnt; i++) ans += possible[i];
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
