#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n], b[n];
  bool assigned[n];
  bool jobs[k + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    assigned[i] = false;
  }
  for (int i = 0; i <= k; i++) jobs[i] = false;
  for (int i = 0; i < n; i++) cin >> b[i];
  map<long long, pair<long long, long long> > m;
  for (int i = 0; i < n; i++) {
    if (m.find(a[i]) != m.end()) {
      long long x = m[a[i]].second;
      long long y = m[a[i]].first;
      if (x < b[i]) {
        assigned[i] = true;
        m[a[i]].first = i;
        m[a[i]].second = b[i];
        assigned[y] = false;
      }
    } else {
      m[a[i]].first = i;
      m[a[i]].second = b[i];
      assigned[i] = true;
    }
    jobs[a[i]] = true;
  }
  long long res = 0;
  priority_queue<long long> q;
  for (int i = 0; i < n; i++) {
    if (!assigned[i]) {
      q.push(-b[i]);
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!jobs[i]) {
      long long x = -q.top();
      res += x;
      q.pop();
    }
  }
  cout << res << "\n";
}
