#include <bits/stdc++.h>
using namespace std;
int h[100010], f[100010], c[100010], dp[2][5010];
unordered_map<int, int> mp, mpp;
int main() {
  cin.tie(0);
  int ans = 0;
  ios::sync_with_stdio(0);
  mp.clear();
  mpp.clear();
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k; j++) {
      cin >> c[i];
      if (!mp[c[i]]) mp[c[i]] = 0;
      mp[c[i]]++;
    }
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    if (!mpp[f[i]]) mpp[f[i]] = 0;
    mpp[f[i]]++;
  }
  for (int i = 1; i <= k; i++) cin >> h[i];
  for (auto it : mpp) {
    int cur = 1, pre = 0;
    int i = it.first, res = 0;
    int t = it.second, m = mp[i];
    memset(dp, 0, sizeof(dp));
    for (int j = 1; j <= t; j++) {
      for (int l = 0; l <= m && l <= j * k; l++) {
        for (int p = 0; p <= k && p <= l; p++)
          if (l - p <= (j - 1) * k)
            dp[cur][l] = max(dp[cur][l], dp[pre][l - p] + h[p]);
        res = max(res, dp[cur][l]);
      }
      swap(cur, pre);
    }
    ans += res;
  }
  cout << ans << endl;
  return 0;
}
