#include <bits/stdc++.h>
using namespace std;
struct node {
  int in, val;
  bool operator<(const node& it) const { return val > it.val; }
} a[100005];
int use[100005];
priority_queue<node> Q;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i].in;
  for (int i = 0; i < n; i++) cin >> a[i].val;
  for (int i = 0; i < n; i++) {
    use[a[i].in]++;
    Q.push(a[i]);
  }
  int cnt = 0;
  for (int i = 1; i <= m; i++) {
    if (use[i] == 0) cnt++;
  }
  long long ans = 0;
  while (!Q.empty() && cnt > 0) {
    node now = Q.top();
    Q.pop();
    if (use[now.in] > 1) {
      use[now.in]--;
      ans += now.val;
      cnt--;
    }
  }
  cout << ans << endl;
  return 0;
}
