#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200;
int defence[MAXN], attack[MAXN], atkno, defno;
int ciel[MAXN], n, m;
bool mark[MAXN];
int solve1() {
  int ret = 0;
  for (int i = 1; i <= min(n, atkno); i++) {
    bool yes = true;
    int temp = 0;
    for (int j = 0; j < i; j++)
      if (ciel[n - 1 - j] < attack[i - 1 - j]) {
        yes = false;
        break;
      }
    if (yes)
      for (int j = 0; j < i; j++) temp += ciel[n - 1 - j] - attack[i - 1 - j];
    if (ret < temp) ret = temp;
  }
  return ret;
}
int solve2() {
  int ptr = 0;
  if (defno != 0)
    for (int i = 0; i < n; i++)
      if (ciel[i] > defence[ptr]) {
        mark[i] = true;
        ptr++;
        if (ptr == defno) break;
      }
  if (ptr != defno) return 0;
  int temp = n;
  for (int i = 0; i < n; i++)
    if (mark[i]) temp--;
  if (temp < atkno) return 0;
  ptr = atkno - 1;
  if (ptr >= 0)
    for (int i = n - 1; i >= 0; i--)
      if (!mark[i] && ciel[i] >= attack[ptr]) {
        ptr--;
        if (ptr == -1) break;
      }
  if (ptr != -1) return 0;
  int ret = 0;
  for (int i = 0; i < n; i++)
    if (!mark[i]) ret += ciel[i];
  for (int i = 0; i < atkno; i++) ret -= attack[i];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    cin >> s;
    int x;
    cin >> x;
    if (s == "ATK")
      attack[atkno++] = x;
    else
      defence[defno++] = x;
  }
  for (int i = 0; i < n; i++) cin >> ciel[i];
  sort(ciel, ciel + n);
  sort(defence, defence + defno);
  sort(attack, attack + atkno);
  cout << max(solve1(), solve2()) << endl;
  return 0;
}
