#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, k, a[maxn], b[maxn], t;
vector<int> c[maxn], tmp;
long long ans;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    c[a[i]].push_back(b[i]);
  }
  for (int i = 1; i <= k; ++i) {
    int siz = c[i].size();
    if (!siz) {
      ++t;
      continue;
    }
    sort(c[i].begin(), c[i].end());
    for (int j = 0; j < siz - 1; ++j) tmp.push_back(c[i][j]);
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < t; ++i) ans += tmp[i];
  return cout << ans << endl, 0;
}
