#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100010];
long long b[100010];
long long res;
vector<pair<long long, int> > v[100010];
vector<long long> ans;
int now;
bool vs[100010];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) v[a[i]].push_back(make_pair(b[i], i));
  memset(vs, false, sizeof(vs));
  now = 0;
  for (int i = 1; i <= k; i++)
    if (v[i].size() != 0) {
      now += 1;
      sort(v[i].begin(), v[i].end());
      int tmp = v[i].size();
      vs[v[i][tmp - 1].second] = true;
    }
  for (int i = 1; i <= n; i++)
    if (vs[i] == false) {
      ans.push_back(b[i]);
    }
  sort(ans.begin(), ans.end());
  res = 0;
  for (int i = now + 1; i <= k; i++) res += ans[i - (now + 1)];
  cout << res;
  return 0;
}
