#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int dp[5001], c[N + 1], p[N + 1], h[501];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n * m; i++) {
    int tmp;
    cin >> tmp;
    c[tmp] += 1;
  }
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    p[tmp] += 1;
  }
  for (int i = 1; i <= m; i++) cin >> h[i];
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    memset(dp, 0, c[i] + 1 << 2);
    for (int j = 1; j <= p[i]; j++)
      for (int k = c[i]; k; k--)
        for (int l = 1; k - l >= 0 && l <= m; l++)
          dp[k] = max(dp[k], dp[k - l] + h[l]);
    ans += dp[c[i]];
  }
  cout << ans << endl;
  return 0;
}
