#include <bits/stdc++.h>
using namespace std;
long long n, k, a[112345], res;
map<long long, long long> m;
set<long long> s;
vector<long long> ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    s.insert(a[i]);
  }
  for (long long i = 0, d; i < n; ++i) {
    cin >> d;
    if (!m.count(a[i])) {
      m[a[i]] = d;
    } else if (m[a[i]] < d) {
      ans.push_back(m[a[i]]);
      m[a[i]] = d;
    } else {
      ans.push_back(d);
    }
  }
  sort(ans.begin(), ans.end());
  for (long long i = s.size(), j = 0; i < k; ++i, ++j) {
    res += ans[j];
  }
  cout << res;
}
