#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int n, m;
  cin >> n >> m;
  vector<int> atk, def;
  string t;
  int val;
  for (int i = 0; i < n; ++i) {
    cin >> t >> val;
    if (t == "ATK")
      atk.push_back(val);
    else
      def.push_back(val);
  }
  vector<int> ciel;
  for (int i = 0; i < m; ++i) {
    cin >> val;
    ciel.push_back(val);
  }
  vector<bool> seenC(m, false);
  int i, j;
  int res = 0, ans = 0;
  for (i = 0; i < ((int)(def).size()); ++i) {
    int mini = -1;
    for (j = 0; j < m; ++j) {
      if (seenC[j]) continue;
      if (ciel[j] > def[i] && (mini == -1 || ciel[mini] > ciel[j])) mini = j;
    }
    if (mini == -1) break;
    seenC[mini] = 1;
  }
  if (i == ((int)(def).size())) {
    for (i = 0; i < ((int)(atk).size()); ++i) {
      int mini = -1;
      for (j = 0; j < m; ++j) {
        if (seenC[j]) continue;
        if (ciel[j] >= atk[i] && (mini == -1 || ciel[mini] > ciel[j])) mini = j;
      }
      if (mini == -1) break;
      seenC[mini] = 1;
      res += ciel[mini] - atk[i];
    }
    if (i == ((int)(atk).size())) {
      for (i = 0; i < m; ++i) {
        if (!seenC[i]) res += ciel[i];
      }
      ans = max(res, ans);
    }
  }
  sort(ciel.rbegin(), ciel.rend());
  sort((atk).begin(), (atk).end());
  for (i = 1; i <= min(((int)(atk).size()), ((int)(ciel).size())); ++i) {
    res = 0;
    for (j = 0; j < i; ++j) {
      if (ciel[j] >= atk[j])
        res += ciel[j] - atk[j];
      else
        break;
    }
    if (j < i)
      break;
    else
      ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
