#include <bits/stdc++.h>
using namespace std;
const int MAX = 102;
const long long oo = 1LL << 40;
int dp[MAX][MAX];
int solve(vector<int> &def, vector<int> &atk) {
  int m = def.size();
  int n = atk.size();
  if (n == 0) return 0;
  int cnt = min(m, n);
  int ans = 0;
  for (int i = 0; i < cnt; ++i) {
    bool ok = true;
    int ret = 0;
    for (int k = 0; k <= i && ok; ++k) {
      ok &= def[m - k - 1] >= atk[k];
      ret += def[m - k - 1] - atk[k];
    }
    if (ok) ans = max(ans, ret);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int N, M, skill;
  string s;
  vector<int> atk;
  vector<int> def;
  vector<int> ceil;
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    cin >> s >> skill;
    if (s == "ATK")
      atk.push_back(skill);
    else
      def.push_back(skill);
  }
  sort(def.begin(), def.end());
  sort(atk.begin(), atk.end());
  for (int i = 0; i < M; ++i) {
    cin >> skill;
    ceil.push_back(skill);
  }
  sort(ceil.begin(), ceil.end());
  int ans = solve(ceil, atk);
  int ind = 0, pos = 0;
  vector<int> rest;
  for (; ind < (int)def.size();) {
    while (pos < M && ceil[pos] <= def[ind]) {
      rest.push_back(ceil[pos]);
      ++pos;
    }
    if (pos >= M)
      break;
    else
      ++pos, ++ind;
  }
  for (; pos < M; ++pos) rest.push_back(ceil[pos]);
  if (ind == (int)def.size()) {
    sort(rest.begin(), rest.end());
    ind = 0, pos = 0, M = rest.size();
    for (; ind < (int)atk.size();) {
      while (pos < M && rest[pos] < atk[ind]) ++pos;
      if (pos >= M)
        break;
      else
        ++pos, ++ind;
    }
    if (ind >= (int)atk.size()) {
      int value = 0;
      for (int i = 0; i < (int)rest.size(); ++i) value += rest[i];
      for (int i = 0; i < (int)atk.size(); ++i) value -= atk[i];
      ans = max(ans, value);
    }
  }
  cout << ans << endl;
  return 0;
}
