#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}
const int N = 5005;
int n, m, c[N], f[N], h[N], g[N], dp[505][N], hh[N * 20], ans;
int cwy[N * 20], wyy[N * 20];
int main() {
  n = read();
  m = read();
  int M = n * m;
  for (int i = 1; i <= M; i++) wyy[c[i] = read()]++;
  for (int i = 1; i <= n; i++) cwy[f[i] = read()]++;
  for (int i = 1; i <= m; i++) h[i] = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= M; j++)
      for (int k = 1; k <= min(m, j); k++)
        dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + h[k]);
  for (int i = 1; i <= (int)1e5; i++) ans += dp[cwy[i]][wyy[i]];
  printf("%d\n", ans);
  return 0;
}
