#include <bits/stdc++.h>
using namespace std;
long long ara[300005], vis[300005];
vector<long long> g[300005];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  while (cin >> n >> k) {
    for (long long i = 1; i <= n; i++) {
      cin >> ara[i];
    }
    for (long long i = 1; i <= n; i++) {
      long long b;
      cin >> b;
      g[ara[i]].push_back(b);
    }
    priority_queue<long long, vector<long long>, greater<long long> > q;
    for (long long i = 1; i <= k; i++) {
      sort(g[i].rbegin(), g[i].rend());
      for (long long j = 0; j < g[i].size(); j++) {
        if (j) q.push(g[i][j]);
      }
    }
    long long ans = 0;
    for (long long i = 1; i <= k; i++) {
      if (g[i].empty()) {
        ans += q.top();
        q.pop();
      }
      g[i].clear();
    }
    cout << ans << endl;
  }
  return 0;
}
