#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
const int INF_INT = 2e9 + 100;
const long long POLTOS = 50;
const long long SOTKA = 100;
const long long P = 1e9 + 7;
const long double eps = 1e-9;
const long long base = 1000 * 1000 * 1000;
const long long M = 3050;
const long long MAXN = 1e6 + 1;
const long long MAXN1 = 2 * 1e2;
const long long N = 2e5 + 1000;
const long double pi = acos(-1);
const long long mod = 1e9 + 7;
const int S_M = 20;
const long long LEN = 96;
const long long DMOD = 500000004;
const long long PR = 32000;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(n);
  for (auto &i : a) {
    cin >> i.first;
  }
  for (auto &i : a) {
    cin >> i.second;
  }
  sort(a.begin(), a.end(),
       [&](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });
  vector<int> used(k + 1, false);
  multiset<int> b;
  for (int i = 0; i < n; ++i) {
    if (used[a[i].first]) {
      b.insert(a[i].second);
    } else {
      used[a[i].first] = 1;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= k; i++)
    if (!used[i]) {
      ans += *b.begin();
      b.erase(b.begin());
    }
  cout << ans;
  return 0;
}
