#include <bits/stdc++.h>
using namespace std;
const long long sz = 1e5 + 4;
vector<long long> job[sz];
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v;
  v.resize(n);
  for (long long i = 0; i < n; ++i) cin >> v[i].first;
  for (long long i = 0; i < n; ++i)
    cin >> v[i].second, job[v[i].first].push_back(v[i].second);
  vector<long long> vk;
  long long ans = 0;
  for (long long i = 1; i < k + 1; ++i) {
    sort(job[i].begin(), job[i].end());
    if ((long long)job[i].size() == 0) ++ans;
    for (long long j = 0; j < (long long)job[i].size() - 1; ++j) {
      vk.push_back(job[i][j]);
    }
  }
  long long ret = 0;
  sort(vk.begin(), vk.end());
  for (long long i = 0; i < ans; ++i) {
    ret += vk[i];
  }
  cout << ret << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
