#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int n, k;
int a[100500];
vector<int> cost[100500];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    cost[a[i] - 1].push_back(x);
  }
  int need = 0;
  vector<int> freeCost;
  for (int i = 0; i < k; ++i) {
    if (cost[i].empty()) ++need;
    nth_element(cost[i].begin(), cost[i].end() - 1, cost[i].end());
    for (int j = 0; j < (int)cost[i].size() - 1; ++j) {
      freeCost.push_back(cost[i][j]);
    }
  }
  partial_sort(freeCost.begin(), freeCost.begin() + need, freeCost.end());
  i64 ans = 0;
  for (int i = 0; i < need; ++i) {
    ans += freeCost[i];
  }
  cout << ans;
  return 0;
}
