#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second << '\n';
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front() << ' ';
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << *_it << ' ';
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  for (auto _it : _m) {
    _out << _it.first << ": " << _it.second << '\n';
  }
  return _out;
}
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
struct cord {
  int x;
};
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> b(n);
  set<int> cif;
  for (int i = 0; i < k; i++) {
    cif.insert(i + 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cif.erase(a[i]);
  }
  cin >> b;
  map<int, multiset<int> > mp;
  for (int i = 0; i < n; i++) {
    int x, y;
    x = a[i];
    y = b[i];
    mp[x].insert(b[i]);
  }
  int m = cif.size();
  multiset<int> ans;
  long long lastsum = 0;
  for (auto x : mp) {
    if (x.second.size() > 1) {
      int i = x.second.size();
      for (auto y : x.second) {
        if (i == 1) break;
        ans.insert(y);
        i--;
      }
    }
  }
  for (auto x : ans) {
    if (m == 0) break;
    lastsum += x;
    m--;
  }
  cout << lastsum;
}
