#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> def, atk, ciel;
  for (int i = 0; i < n; ++i) {
    string type;
    int val;
    cin >> type >> val;
    if (type[0] == 'A')
      atk.push_back(val);
    else
      def.push_back(val);
  }
  for (int i = 0, val; i < m; ++i) {
    cin >> val;
    ciel.push_back(val);
  }
  sort(def.begin(), def.end());
  sort(atk.begin(), atk.end());
  sort(ciel.begin(), ciel.end());
  int mx = 0;
  for (int c = 1; c <= min(atk.size(), ciel.size()); ++c) {
    int sm = 0;
    for (int i = 0; i < c; ++i) sm += max(0, ciel[m - c + i] - atk[i]);
    mx = max(mx, sm);
  }
  int ind, all_sm = 0;
  for (ind = 0; ind < def.size(); ++ind) {
    auto it = upper_bound(ciel.begin(), ciel.end(), def[ind]);
    if (it == ciel.end()) break;
    ciel.erase(it);
  }
  if (ind == def.size()) {
    for (ind = atk.size() - 1; ind >= 0; --ind) {
      if (ciel.empty() || ciel.back() < atk[ind]) break;
      all_sm += ciel.back() - atk[ind];
      ciel.pop_back();
    }
    mx =
        max(mx, (ind < 0) * (all_sm + accumulate(ciel.begin(), ciel.end(), 0)));
  }
  cout << mx << endl;
  return 0;
}
