#include <bits/stdc++.h>
using namespace std;
char atk[] = "ATK";
int enmy[110], n;
int my[110], m;
vector<int> A, D;
int work1() {
  int i;
  int ans = 0, p = 0;
  for (i = m; i >= 1; i--) {
    if (p < A.size() && my[i] > A[p]) {
      ans += my[i] - A[p];
      p++;
    }
  }
  return ans;
}
int work2() {
  int ans = 0, i, pa = 0, pd = 0;
  int used[210];
  for (i = 1; i <= m; i++) used[i] = 0;
  for (i = 1; i <= m; i++) {
    if (pd < D.size() && my[i] > D[pd]) {
      used[i] = 1;
      pd++;
    }
  }
  if (pd != D.size()) return ans;
  for (i = 1; i <= m; i++) {
    if (used[i]) continue;
    if (pa < A.size() && my[i] >= A[pa]) {
      ans += my[i] - A[pa];
      used[i] = 1;
      pa++;
    }
  }
  if (pa != A.size()) return ans;
  for (i = 1; i <= m; i++)
    if (!used[i]) ans += my[i];
  return ans;
}
int main() {
  int i, j;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      char s[5];
      cin >> s >> enmy[i];
      if (strcmp(s, atk) == 0)
        A.push_back(enmy[i]);
      else
        D.push_back(enmy[i]);
    }
    sort(A.begin(), A.end());
    sort(D.begin(), D.end());
    for (i = 1; i <= m; i++) cin >> my[i];
    sort(my + 1, my + m + 1);
    int res1 = work1();
    int res2 = work2();
    cout << max(res1, res2) << endl;
  }
  return 0;
}
