#include <bits/stdc++.h>
using namespace std;
int n, m, atk, def;
int a[105], b[105], c[105];
bool vis[105];
int gen() {
  int ans = 0;
  for (int i = 0, j = m - 1; i < atk && j >= 0; i++, j--)
    if (c[j] >= a[i]) ans += (c[j] - a[i]);
  return ans;
}
bool poss() {
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < def; i++) {
    bool flag = 1;
    for (int j = 0; j < m; j++)
      if (c[j] > b[i] && !vis[j]) {
        vis[j] = 1;
        flag = 0;
        break;
      }
    if (flag) return 0;
  }
  for (int i = 0; i < atk; i++) {
    bool flag = 1;
    for (int j = 0; j < m; j++)
      if (c[j] >= a[i] && !vis[j]) {
        vis[j] = 1;
        flag = 0;
        break;
      }
    if (flag) return 0;
  }
  return 1;
}
int all() {
  if (!poss()) return 0;
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < def; i++)
    for (int j = 0; j < m; j++)
      if (c[j] > b[i] && !vis[j]) {
        vis[j] = 1;
        break;
      }
  int ans = 0;
  for (int i = 0; i < m; i++)
    if (!vis[i]) ans += c[i];
  for (int i = 0; i < atk; i++) ans -= a[i];
  return ans;
}
int main() {
  string s;
  cin >> n >> m;
  atk = def = 0;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "ATK")
      cin >> a[atk++];
    else
      cin >> b[def++];
  }
  for (int i = 0; i < m; i++) cin >> c[i];
  sort(a, a + atk);
  sort(b, b + def);
  sort(c, c + m);
  cout << max(gen(), all()) << '\n';
  return 0;
}
