#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<long long> b(n);
  vector<vector<pair<long long, long long>>> d(k);
  for (auto i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (auto i = 0; i < n; ++i) {
    cin >> b[i];
    d[a[i] - 1].push_back(make_pair(b[i], i));
  }
  vector<long long> others;
  int count = 0;
  for (auto i = 0; i < k; ++i) {
    if (d[i].size() == 0) {
      ++count;
    }
    sort(d[i].rbegin(), d[i].rend());
    for (auto j = 1; j < d[i].size(); ++j) {
      others.push_back(d[i][j].first);
    }
  }
  sort(others.begin(), others.end());
  long long ans = 0;
  for (auto i = 0; i < count; ++i) {
    ans += others[i];
  }
  cout << ans;
  return 0;
}
