#include <bits/stdc++.h>
using namespace std;
int match(vector<int> &s, vector<int> &l) {
  int i = 0, j = 0;
  for (; i < s.size(); i++) {
    for (; j < l.size(); j++) {
      if (s[i] <= l[j]) {
        break;
      }
    }
    if (j == l.size()) break;
    j++;
  }
  return i;
}
int main(void) {
  int n, m;
  vector<int> attack, defence, all, ciel;
  string pos;
  int strength;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> pos >> strength;
    if (pos == "ATK") {
      attack.push_back(strength);
      all.push_back(strength);
    } else {
      defence.push_back(strength + 1);
      all.push_back(strength + 1);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> strength;
    ciel.push_back(strength);
  }
  sort(attack.begin(), attack.end());
  sort(defence.begin(), defence.end());
  sort(all.begin(), all.end());
  sort(ciel.begin(), ciel.end());
  int a = 0, b = 0;
  int k = match(attack, ciel);
  for (int i = 0; i < k; i++) {
    if (ciel[ciel.size() - i - 1] - attack[i] < 0) break;
    a += ciel[ciel.size() - i - 1];
    a -= attack[i];
  }
  if (match(all, ciel) == all.size()) {
    for (int i = 0; i < ciel.size(); i++) b += ciel[i];
    for (int i = 0; i < attack.size(); i++) b -= attack[i];
    int j = 0;
    for (int i = 0; i < defence.size(); i++) {
      while (1) {
        if (defence[i] <= ciel[j]) {
          b -= ciel[j];
          j++;
          break;
        }
        j++;
      }
    }
  }
  cout << max(a, b) << endl;
  return 0;
}
