#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long b[m];
  vector<long long> atk;
  vector<long long> def;
  for (long long i = 0, _n = (n); i < _n; i++) {
    string pos;
    long long a;
    cin >> pos >> a;
    if (pos == "ATK")
      atk.push_back(a);
    else
      def.push_back(a);
  }
  for (long long i = 0, _n = (m); i < _n; i++) {
    cin >> b[i];
  }
  long long allc = 0;
  sort(b, b + m);
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  long long p1 = 0;
  long long used[m];
  memset((used), 0, sizeof((used)));
  bool poss = true;
  for (long long i = 0, _n = (def.size()); i < _n; i++) {
    while (p1 < m && b[p1] <= def[i]) {
      p1++;
    }
    if (p1 != m) {
      used[p1] = 1;
      p1++;
    } else {
      poss = false;
      break;
    }
  }
  bool poss2 = true;
  p1 = 0;
  if (poss) {
    for (long long i = 0, _n = (atk.size()); i < _n; i++) {
      while (p1 < m && (b[p1] < atk[i] || used[p1] == 1)) {
        p1++;
      }
      if (p1 != m) {
        allc += b[p1] - atk[i];
        used[p1] = 1;
        p1++;
      } else {
        poss2 = false;
        break;
      }
    }
  } else
    poss2 = false;
  if (poss2) {
    for (long long i = 0, _n = (m); i < _n; i++) {
      if (used[i] == 0) allc += b[i];
    }
  }
  long long allnc = 0;
  long long x = min(m, (long long)atk.size());
  long long y = m - 1;
  for (long long i = 0, _n = (x); i < _n; i++) {
    if (b[y] > atk[i])
      allnc = allnc + b[y] - atk[i];
    else
      break;
    y--;
  }
  cout << max(allc, allnc) << endl;
}
