#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const int maxn = 105;
vector<int> a, d, s;
bool vis[maxn];
char str[maxn];
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    int x;
    scanf("%d", &x);
    if (strcmp(str, "ATK") == 0) {
      a.push_back(x);
    } else {
      d.push_back(x);
    }
  }
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    s.push_back(x);
  }
  sort(a.begin(), a.end());
  sort(d.begin(), d.end());
  sort(s.begin(), s.end());
  int na = a.size(), nd = d.size(), ns = s.size();
  int ans = 0, pos = 0;
  if (na > 0) {
    for (int i = ns - 1; i >= 0; i--) {
      if (s[i] >= a[pos]) {
        ans += s[i] - a[pos];
        pos++;
        if (pos == na) break;
      }
    }
  }
  int ans2 = 0;
  pos = 0;
  if (nd > 0) {
    for (int i = 0; i < ns; i++) {
      if (s[i] > d[pos]) {
        vis[i] = 1;
        pos++;
        if (pos == nd) break;
      }
    }
  }
  if (pos == nd) {
    pos = 0;
    if (na > 0) {
      for (int i = 0; i < ns; i++) {
        if (!vis[i] && s[i] >= a[pos]) {
          ans2 += s[i] - a[pos];
          pos++;
          vis[i] = 1;
          if (pos == na) break;
        }
      }
    }
    if (pos == na) {
      for (int i = 0; i < ns; i++)
        if (!vis[i]) ans2 += s[i];
    }
  }
  printf("%d\n", max(ans, ans2));
  return 0;
}
