#include <bits/stdc++.h>
using namespace std;
long long n, k, A[100005], B[100005], C[100005], sum, val;
pair<long long, long long> E[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    C[A[i]]++;
  }
  for (int i = 1; i <= k; i++) {
    if (C[i] == 0) val++;
  }
  for (int i = 1; i <= n; i++) {
    cin >> B[i];
    E[i].first = B[i];
    E[i].second = A[i];
  }
  sort(E + 1, E + n + 1);
  k = 1;
  for (int i = 1; k <= val; i++) {
    if (C[E[i].second] > 1) {
      sum += E[i].first;
      C[E[i].second]--;
      k++;
    }
  }
  cout << sum << '\n';
}
