#include <bits/stdc++.h>
using namespace std;
int find(vector<int>& v, int val) {
  int l = 0, r = int((v).size()) - 1, mid;
  if (v[l] > val) return 0;
  if (v[r] <= val) return -1;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (v[mid] > val)
      r = mid;
    else
      l = mid;
  }
  return r;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> atk, def, str;
  while (n--) {
    string s;
    int s1;
    cin >> s >> s1;
    if (s[0] == 'A')
      atk.push_back(s1);
    else
      def.push_back(s1);
  }
  while (m--) {
    int s1;
    cin >> s1;
    str.push_back(s1);
  }
  sort((str).begin(), (str).end());
  sort((def).begin(), (def).end());
  sort((atk).begin(), (atk).end());
  int s1 = 0, s2 = 0, mx = 0;
  for (int i = 0; i < min(int((str).size()), int((atk).size())); i++) {
    if (str[int((str).size()) - 1 - i] >= atk[0] &&
        str[int((str).size()) - 1] >= atk[i]) {
      s1 += str[int((str).size()) - 1 - i];
      s2 += atk[i];
      mx = max(mx, s1 - s2);
    }
  }
  if (int((atk).size()) + int((def).size()) > int((str).size())) {
    cout << mx << endl;
    return 0;
  }
  for (int i = 0; i < (int((def).size())); ++i) {
    int ind = find(str, def[i]);
    if (ind == -1) {
      cout << mx << endl;
      return 0;
    }
    str.erase(str.begin() + ind, str.begin() + ind + 1);
  }
  s1 = s2 = 0;
  for (int i = 0; i < (int((atk).size())); ++i) {
    if (str[int((str).size()) - i - 1] >= atk[int((atk).size()) - i - 1]) {
      s2 += atk[int((atk).size()) - i - 1];
    } else {
      cout << mx << endl;
      return 0;
    }
  }
  for (int i = 0; i < (int((str).size())); ++i) s1 += str[i];
  mx = max(mx, s1 - s2);
  cout << mx << endl;
  return 0;
}
