#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> jiroat, jirodef, ceil(m);
  vector<pair<long long int, long long int>> jirotot;
  for (int i = 0; i < n; i++) {
    string ch;
    long long int str;
    cin >> ch >> str;
    long long int type = 0;
    if (ch == "ATK")
      jiroat.push_back(str);
    else {
      jirodef.push_back(str);
      type = 1;
    }
    jirotot.push_back(pair<long long int, long long int>(str, type));
  };
  for (long long int i = 0; i < m; i++) cin >> ceil[i];
  ;
  sort(jiroat.begin(), jiroat.end());
  sort(jirodef.begin(), jirodef.end());
  sort(jirotot.begin(), jirotot.end());
  sort(ceil.begin(), ceil.end());
  long long int flag = 0;
  long long int ans = 0;
  if (m >= n) {
    long long int j = n - 1;
    long long int i = m - 1;
    while (i > -1) {
      if (j == -1) break;
      if (jirotot[j].second == 1) {
        if (ceil[i] <= jirotot[j].first) {
          flag = 1;
          break;
        }
      } else {
        if (ceil[i] < jirotot[j].first) {
          flag = 1;
          break;
        }
      }
      j--;
      i--;
    }
    if (flag == 0) {
      for (int i = 0; i < m; i++) ans += ceil[i];
      for (int j = 0; j < (int)((jiroat).size()); j++) {
        ans -= jiroat[j];
      }
      set<pair<long long int, long long int>> util;
      for (int i = 0; i < m; i++)
        util.insert(pair<long long int, long long int>(ceil[i], i));
      for (int i = 0; i < (int)((jirodef).size()); i++) {
        auto it = util.lower_bound(
            pair<long long int, long long int>(jirodef[i], inf));
        ans -= it->first;
        util.erase(it);
      }
    }
  } else {
    flag = 1;
  }
  if (flag == 1) ans = 0;
  long long int ans1 = 0;
  long long int j = 0;
  for (int i = m - 1; i > -1; i--) {
    if (j == (int)((jiroat).size())) break;
    ans1 += max(ceil[i] - jiroat[j], (long long int)0);
    j++;
  }
  cout << max(ans, ans1) << "\n";
}
