#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = (long long)INF * INF;
const int MAX = 100 * 1000 + 7;
int a[MAX];
int b[MAX];
vector<int> c[MAX];
vector<int> d;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = (0); i < (n); ++i) {
    scanf("%d", a + i);
  }
  for (int i = (0); i < (n); ++i) {
    scanf("%d", b + i);
  }
  for (int i = (0); i < (n); ++i) c[a[i]].push_back(b[i]);
  int unused = 0;
  for (int i = (1); i < (k + 1); ++i) {
    if (c[i].empty()) unused++;
    sort(c[i].begin(), c[i].end());
    for (int j = (0); j < ((long long)((c[i]).size()) - 1); ++j)
      d.push_back(c[i][j]);
  }
  sort(d.begin(), d.end());
  long long ans = 0;
  for (int i = (0); i < (unused); ++i) ans += d[i];
  printf("%lld", ans);
  return 0;
}
