#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
vector<int> Atk, Def, Ceil;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  while (n--) {
    string s;
    cin >> s;
    int x;
    cin >> x;
    if (s == "ATK")
      Atk.push_back(x);
    else
      Def.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    Ceil.push_back(x);
  }
  sort(Atk.begin(), Atk.end());
  sort(Def.begin(), Def.end());
  sort(Ceil.begin(), Ceil.end());
  int Res1 = 0, Res2 = 0;
  for (int i = 0; i < min(Ceil.size(), Atk.size()); i++) {
    if (Ceil[m - i - 1] <= Atk[i]) break;
    Res1 += Ceil[m - i - 1] - Atk[i];
  }
  for (int i = 0; i < Def.size(); i++) {
    int k = 0;
    while (k < Ceil.size() && Ceil[k] <= Def[i]) k++;
    if (k == Ceil.size()) {
      cout << Res1 << "\n", exit(0);
    }
    Ceil.erase(Ceil.begin() + k);
  }
  for (int i = 0; i < Atk.size(); i++) {
    int k = 0;
    while (k < Ceil.size() && Ceil[k] < Atk[i]) k++;
    if (k == Ceil.size()) {
      cout << Res1 << "\n", exit(0);
    }
    Res2 += Ceil[k] - Atk[i];
    Ceil.erase(Ceil.begin() + k);
  }
  for (auto x : Ceil) Res2 += x;
  cout << max(Res1, Res2) << "\n";
  return 0;
}
