#include <bits/stdc++.h>
using namespace std;
ofstream fout("test.out");
ifstream fin("test.in");
const long long MX = 2e6 + 100, INF = 1e18, INF2 = -1e18, D = 1e9 + 7;
long long n, m, arr[MX], arr1[MX], fa[20], cnt, flg, ans, del = 10433,
                                                          dp[501][5001];
string s;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n * m; i++) {
    long long a;
    cin >> a;
    arr[a]++;
  }
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    arr1[a]++;
  }
  for (long long i = 0; i < m; i++) {
    cin >> fa[i];
  }
  for (long long i = 1; i <= m * n; i++) {
    dp[1][i] = max(fa[i - 1], dp[1][i - 1]);
  }
  for (long long i = 2; i <= n; i++) {
    for (long long j = 1; j <= m * n; j++) {
      long long big = dp[i - 1][j];
      for (long long k = 1; k <= min(j, m); k++) {
        big = max(big, fa[k - 1] + dp[i - 1][j - k]);
      }
      dp[i][j] = big;
    }
  }
  for (long long i = 0; i < 1000001; i++) {
    if (arr[i] > 0 && arr1[i] > 0) {
      ans += dp[arr1[i]][arr[i]];
    }
  }
  cout << ans << "\n";
  return 0;
}
