#include <bits/stdc++.h>
using namespace std;
vector<int> atk, def;
int a[105];
bool mark[105];
int n, m;
int strategy1() {
  for (int i = 0; i < def.size(); i++) {
    int x = def[i];
    bool flag = false;
    for (int j = 0; j < m; j++)
      if (a[j] > def[i] && !mark[j]) {
        mark[j] = true;
        flag = true;
        break;
      }
    if (!flag) return 0;
  }
  int ans = 0;
  for (int i = 0; i < atk.size(); i++) {
    int x = atk[i];
    bool flag = false;
    for (int j = 0; j < m; j++)
      if (a[j] >= atk[i] && !mark[j]) {
        mark[j] = true;
        ans += a[j] - atk[i];
        flag = true;
        break;
      }
    if (!flag) return 0;
  }
  for (int i = 0; i < m; i++)
    if (!mark[i]) ans += a[i];
  return ans;
}
int strategy2() {
  int ans = 0;
  for (int t = 1; t <= min(int(atk.size()), m); t++) {
    int sum = 0;
    for (int i = 0; i < t; i++) {
      if (a[m - t + i] < atk[i]) return ans;
      sum += a[m - t + i] - atk[i];
    }
    ans = max(sum, ans);
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int a;
    cin >> a;
    if (s == "ATK")
      atk.push_back(a);
    else
      def.push_back(a);
  }
  for (int i = 0; i < m; i++) cin >> a[i];
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(a, a + m);
  int ans = max(strategy1(), strategy2());
  cout << ans << endl;
  return 0;
}
