#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m;
bool f[2][N];
bool used[N];
vector<int> jiro[2];
vector<int> ciel;
int ans1, ans2;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    string s;
    int p;
    cin >> s >> p;
    jiro[(s == "DEF" ? 0 : 1)].push_back(p);
  }
  for (int i = 0; i < m; ++i) {
    int p;
    cin >> p;
    ciel.push_back(p);
  }
  sort(jiro[0].begin(), jiro[0].end());
  sort(jiro[1].begin(), jiro[1].end());
  sort(ciel.begin(), ciel.end());
  for (int i = 0; i < m; ++i) {
    bool open = 1;
    for (int k = 0; k < 2; ++k)
      for (int j = 0; j < (int)jiro[k].size(); ++j) {
        if (f[k][j]) continue;
        open = 0;
        if (k == 0 ? ciel[i] > jiro[k][j] : ciel[i] >= jiro[k][j]) {
          f[k][j] = 1;
          used[i] = 1;
          ans1 += (k == 1 ? ciel[i] - jiro[k][j] : 0);
          k = 2;
          break;
        }
      }
    if (open) {
      for (int i = 0; i < m; ++i)
        if (!used[i]) ans1 += ciel[i];
      break;
    }
  }
  for (int i = m - 1; i >= 0; --i)
    if (m - i - 1 < (int)jiro[1].size() && ciel[i] >= jiro[1][m - i - 1])
      ans2 += ciel[i] - jiro[1][m - i - 1];
    else
      break;
  cout << max(ans1, ans2) << endl;
  return 0;
}
