#include <bits/stdc++.h>
using namespace std;
long long NeedJob(vector<pair<long long, long long> > ider, long long k,
                  long long n) {
  long long m = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (ider[i].first != ider[i + 1].first)
      m += (ider[i + 1].first - ider[i].first - 1);
  }
  if (ider[0].first != 1) m += (ider[0].first - 1);
  if (ider[n - 1].first != k) m += (k - ider[n - 1].first);
  return m;
}
void Solves() {
  long long n, k, perjob;
  cin >> n >> k;
  vector<pair<long long, long long> > ider(n);
  for (long long i = 0; i < n; i++) cin >> ider[i].first;
  for (long long i = 0; i < n; i++) cin >> ider[i].second;
  sort(ider.begin(), ider.end());
  if (NeedJob(ider, k, n) == 0) {
    cout << "0";
    return;
  } else {
    long perjob = NeedJob(ider, k, n);
    vector<long long> persua0, persua;
    for (long long i = 0; i < n; i++) {
      if (ider[i].first == ider[i + 1].first && i + 1 < n) {
        persua.push_back(ider[i].second);
        while (ider[i + 1].first == ider[i].first && i + 1 < n) {
          i++;
          persua.push_back(ider[i].second);
        }
        sort(persua.begin(), persua.end());
        persua.pop_back();
        for (long long j = 0; j < persua.size(); j++)
          persua0.push_back(persua[j]);
        persua.clear();
      }
    }
    sort(persua0.begin(), persua0.end());
    long long count = 0;
    for (long long j = 0; j < perjob; j++) count += persua0[j];
    cout << count << endl;
  }
}
int main() {
  Solves();
  return 0;
}
