#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using dbl = long double;
using pii = pair<int, int>;
const int N = 1e5 + 10;
int a[N];
int b[N];
int minId[N];
vector<int> toUse;
void solve() {
  int n, k;
  memset(minId, -1, sizeof minId);
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < n; ++i) {
    if (minId[a[i]] == -1 || b[minId[a[i]]] < b[i]) {
      if (minId[a[i]] != -1) toUse.push_back(b[minId[a[i]]]);
      minId[a[i]] = i;
    } else {
      toUse.push_back(b[i]);
    }
  }
  sort(toUse.begin(), toUse.end());
  ll ans = 0;
  int ptr = 0;
  (void)0;
  (void)0;
  for (int i = 0; i < k; ++i) {
    if (minId[i] == -1) ans += toUse[ptr++];
  }
  printf("%lld\n", ans);
}
int main() {
  solve();
  (void)0;
}
