#include <bits/stdc++.h>
const int maxi = 2000000000;
const int maxq = 1000000000;
const double eps = 1e-10;
const double pi = 3.1415926535897932;
const double inf = 1e+18;
const int mo = 1000000007;
using namespace std;
vector<int> my, def, at;
bool used[555555];
int n, m, x, ans;
char ch;
int kill_def() {
  int ans = 0;
  for (int i = 0; i < def.size(); i++) {
    bool ok = false;
    for (int j = 0; j < my.size(); j++)
      if (my[j] > def[i] && !used[j]) {
        used[j] = true;
        ok = true;
        break;
      }
    if (!ok) return 0;
  }
  for (int i = 0; i < at.size(); i++) {
    bool ok = false;
    for (int j = 0; j < my.size(); j++)
      if (my[j] >= at[i] && !used[j]) {
        used[j] = true;
        ans = ans + my[j] - at[i];
        ok = true;
        break;
      }
    if (!ok) return ans;
  }
  for (int i = 0; i < my.size(); i++)
    if (!used[i]) ans += my[i];
  return ans;
}
int not_kill_def(int n) {
  memset(used, 0, sizeof(used));
  int ans = 0;
  for (int i = n; i >= 0; i--) {
    bool ok = false;
    for (int j = my.size() - 1; j >= 0; j--)
      if (my[j] >= at[i] && !used[j]) {
        used[j] = true;
        ans = ans + my[j] - at[i];
        ok = true;
        break;
      }
    if (!ok) return ans;
  }
  return ans;
}
int main() {
  cin >> n >> m;
  scanf("\n");
  for (int i = 1; i <= n; i++) {
    scanf("%c%c%c %d\n", &ch, &ch, &ch, &x);
    if (ch == 'K') at.push_back(x);
    if (ch == 'F') def.push_back(x);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &x);
    my.push_back(x);
  }
  sort(my.begin(), my.end());
  sort(at.begin(), at.end());
  sort(def.begin(), def.end());
  int ans = -maxi;
  ans = max(ans, kill_def());
  for (int i = 0; i < at.size(); i++) ans = max(ans, not_kill_def(i));
  cout << ans << endl;
  return 0;
}
