#include <bits/stdc++.h>
using namespace std;
vector<int> v[10], t;
bool marked[110];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int stg;
    cin >> stg;
    if (s == "DEF")
      v[0].push_back(stg);
    else
      v[1].push_back(stg);
  }
  sort(v[0].begin(), v[0].end());
  sort(v[1].begin(), v[1].end());
  for (int i = 0; i < m; i++) {
    int stg;
    cin >> stg;
    t.push_back(stg);
  }
  sort(t.begin(), t.end());
  int s1 = 0, ans = 0;
  bool good = true;
  for (int i = 0; i < v[0].size(); i++) {
    bool ok = false;
    for (int j = 0; j < t.size(); j++)
      if (!marked[j] && v[0][i] < t[j]) {
        marked[j] = true;
        ok = true;
        break;
      }
    good &= ok;
  }
  for (int i = 0; i < v[1].size(); i++) {
    bool ok = false;
    for (int j = 0; j < t.size(); j++)
      if (!marked[j] && v[1][i] <= t[j]) {
        s1 += t[j] - v[1][i];
        marked[j] = true;
        ok = true;
        break;
      }
    good &= ok;
  }
  if (good) {
    for (int j = 0; j < t.size(); j++)
      if (!marked[j]) s1 += t[j];
    ans = max(ans, s1);
  }
  for (int i = 0; i < min(t.size(), v[1].size()); i++) {
    bool good = true;
    int s2 = 0;
    for (int j = 0; j <= i; j++)
      if (t[((m - 1) - i) + j] >= v[1][j])
        s2 += t[((m - 1) - i) + j] - v[1][j];
      else {
        good = false;
        break;
      }
    if (good) ans = max(ans, s2);
  }
  cout << ans << endl;
}
