#include <bits/stdc++.h>
using namespace std;
string char_to_str(char c) {
  string tem(1, c);
  return tem;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, k;
  cin >> n >> k;
  long long a[n], p[n];
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<long long> v[k + 1];
  for (long long i = 0; i < n; ++i) {
    cin >> p[i];
    v[a[i]].push_back(p[i]);
  }
  vector<long long> ans;
  long long c = 0;
  long long va = 0;
  for (long long i = 1; i <= k; ++i) {
    if (v[i].size() == 0) {
      ++c;
    } else {
      sort(v[i].begin(), v[i].end());
      for (long long j = 0; j < v[i].size() - 1; ++j) {
        ans.push_back(v[i][j]);
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (long long i = 0; i < c; ++i) {
    va += ans[i];
  }
  cout << va;
}
