#include <bits/stdc++.h>
using namespace std;
struct e {
  int a, b;
};
e p[100005];
int n, k;
bool use[100005];
priority_queue<int, vector<int>, std::greater<int> > Q;
bool criteriu(e a, e b) { return a.b > b.b; }
long long af;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i].a);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i].b);
  }
  sort(p + 1, p + n + 1, criteriu);
  for (int i = 1; i <= n; i++) {
    if (!use[p[i].a]) {
      use[p[i].a] = true;
    } else {
      Q.push(p[i].b);
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!use[i]) {
      af += Q.top();
      Q.pop();
    }
  }
  printf("%lld\n", af);
  return 0;
}
