#include <bits/stdc++.h>
using namespace std;
ifstream fi("test.txt");
ifstream fir("inp.txt");
ofstream fo("out.txt");
const long long MOD = 1e9 + 7;
const long long base = 269;
const int ooi = 1 << 30;
const int N = 1e5 + 5;
long long n, m, q, k, pos, rs, t, T, cnt, rs1;
long long maxx = -1e9, minn = 1e9;
long long a[N], b[N];
vector<long long> c[N];
int main() {
  cin >> n >> k;
  for (long long(i) = 0; (i) < (n); (i)++) {
    cin >> a[i];
  }
  for (long long(i) = 0; (i) < (n); (i)++) {
    cin >> b[i];
    c[a[i]].push_back(b[i]);
  }
  for (long long(i) = 1; (i) <= (k); (i)++) {
    sort(c[i].begin(), c[i].end());
    if (c[i].size()) c[i].pop_back(), cnt++;
  }
  cnt = k - cnt;
  vector<long long> ans;
  for (long long(i) = 1; (i) <= (k); (i)++) {
    for (long long(j) = 0; (j) < (c[i].size()); (j)++) ans.push_back(c[i][j]);
  }
  sort(ans.begin(), ans.end());
  for (long long(i) = 0; (i) < (cnt); (i)++) rs += ans[i];
  cout << rs;
}
