#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 5;
vector<int> vec[MAXN];
int A[MAXN], B[MAXN];
int n, k;
void solve() {
  cin >> n >> k;
  for (int i = (1); i < (n + 1); ++i) {
    cin >> A[i];
  }
  for (int i = (1); i < (n + 1); ++i) {
    cin >> B[i];
  }
  for (int i = (1); i < (n + 1); ++i) {
    vec[A[i]].push_back(B[i]);
  }
  vector<int> T;
  int need = 0;
  for (int i = (1); i < (k + 1); ++i) {
    if (vec[i].empty()) {
      need++;
    } else {
      sort((vec[i]).begin(), (vec[i]).end());
      vec[i].pop_back();
      for (int x : vec[i]) {
        T.push_back(x);
      }
    }
  }
  assert((int)(T).size() >= need);
  sort((T).begin(), (T).end());
  long long ans = 0;
  for (int i = (0); i < (need); ++i) {
    ans += T[i];
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
