#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MAXN = 100005;
const long long MOD = 1000000007;
void base() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
pair<int, int> arr[100005];
int occ[100005];
int main() {
  base();
  int n, k, temp, need = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    arr[i].second = temp;
    occ[temp]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> temp;
    arr[i].first = temp;
  }
  for (int i = 1; i <= k; i++) {
    if (occ[i] == 0) need++;
  }
  sort(arr, arr + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (occ[arr[i].second] > 1 && need > 0) {
      occ[arr[i].second]--;
      need--;
      ans += (long long)arr[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
