#include <bits/stdc++.h>
using namespace std;
vector<int> c[111111];
int a[111111];
int b[111111];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  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) c[a[i]].push_back(b[i]);
  for (int i = 1; i <= k; ++i) sort(c[i].rbegin(), c[i].rend());
  int need = 0;
  vector<int> v;
  for (int i = 1; i <= k; ++i) {
    if (c[i].size()) need++;
    for (int j = 1; j < c[i].size(); ++j) v.push_back(c[i][j]);
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  k -= need;
  for (int i = 0; i < k && i < v.size(); ++i) sum += v[i];
  cout << sum;
}
