#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n, k;
  cin >> n >> k;
  int total = 0;
  vi jobs(k, 0);
  multiset<ll> s;
  vi select(n);
  for (auto& x : select) {
    cin >> x;
    --x;
  }
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (jobs[select[i]] == 0) {
      jobs[select[i]] = a;
      total++;
    } else {
      if (jobs[select[i]] < a) {
        s.insert(jobs[select[i]]);
        jobs[select[i]] = a;
      } else {
        s.insert(a);
      }
    }
  }
  ll sol = 0;
  for (auto x : s) {
    if (total == k) break;
    sol += x;
    total++;
    if (total == k) break;
  }
  cout << sol << endl;
}
