#include <bits/stdc++.h>
using namespace std;
vector<int> atk, def;
vector<int> p2;
vector<bool> used;
int main() {
  int n, m;
  int res1, res2;
  res1 = res2 = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string str;
    int v;
    cin >> str >> v;
    if (str.compare("DEF")) {
      res2 -= v;
      atk.push_back(v);
    } else
      def.push_back(v);
  }
  for (int i = 0; i < m; i++) {
    int v;
    cin >> v;
    p2.push_back(v);
    res2 += v;
  }
  used.assign(m, 0);
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(p2.begin(), p2.end());
  for (int i = 0; i < m && i < atk.size(); i++) {
    if (atk[i] > p2[m - i - 1])
      break;
    else
      res1 += (p2[m - i - 1] - atk[i]);
  }
  bool f = true;
  for (int i = 0, j = 0; i < def.size(); i++) {
    for (; p2[j] <= def[i] && j < m; j++) {
    }
    if (j == m) {
      f = false;
      break;
    }
    res2 -= p2[j];
    used[j++] = true;
  }
  for (int i = 0, j = 0; i < atk.size(); i++) {
    for (; (atk[i] > p2[j] || used[j]) && j < m; j++) {
    }
    if (j == m) {
      f = false;
      break;
    }
  }
  if (f) res1 = max(res1, res2);
  cout << res1 << endl;
  return 0;
}
