#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> ciel, atk, dfn;
bool vis[105];
int main() {
  int i, j, t, k;
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 0; i < n; i++) {
    string ss;
    cin >> ss >> t;
    if (ss == "ATK")
      atk.push_back(t);
    else
      dfn.push_back(t);
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &t);
    ciel.push_back(t);
  }
  sort(ciel.begin(), ciel.end());
  sort(atk.begin(), atk.end());
  int ans = 0;
  for (i = 1; i <= atk.size(); i++) {
    if (i > ciel.size()) break;
    j = 0, k = ciel.size() - 1;
    t = 0;
    for (; j < i; j++, k--) {
      if (ciel[k] < atk[j]) break;
      t += (ciel[k] - atk[j]);
    }
    ans = max(ans, t);
  }
  sort(dfn.begin(), dfn.end());
  j = 0;
  for (i = 0; i < dfn.size(); i++) {
    for (; j < m; j++) {
      if (ciel[j] > dfn[i] && !vis[j]) {
        vis[j] = 1;
        break;
      }
    }
    if (j == m) return cout << ans << endl, 0;
  }
  t = 0, j = 0;
  for (i = 0; i < atk.size(); i++) {
    for (; j < m; j++) {
      if (ciel[j] >= atk[i] && !vis[j]) {
        vis[j] = 1;
        t += (ciel[j] - atk[i]);
        break;
      }
    }
    if (j == m) return cout << ans << endl, 0;
  }
  for (i = 0; i < m; i++)
    if (!vis[i]) t += ciel[i];
  cout << max(ans, t);
  return 0;
}
