#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int FCB = 1e9 + 7;
long long int prime = 119;
long long int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<long long int> atk, def, vv;
long long int ans1 = 0, ans2 = 0;
void doit1() {
  long long int aa = vv.size();
  long long int bb = atk.size();
  for (long long int i = 0; i < min(aa, bb); i++) {
    if (vv[i] >= atk[i])
      ans1 += (vv[i] - atk[i]);
    else
      break;
  }
}
void doit2() {
  long long int aa = vv.size();
  long long int bb = atk.size();
  long long int cc = def.size();
  vector<bool> vis(aa, 0);
  reverse(vv.begin(), vv.end());
  long long int idx1 = 0, idx2 = 0;
  for (long long int i = 0; i < aa; i++) {
    if (idx1 < cc && vv[i] > def[idx1]) vis[i] = 1, idx1++;
  }
  if (idx1 != cc) return;
  for (long long int i = 0; i < aa; i++) {
    if (vis[i])
      continue;
    else if (idx2 < bb && vv[i] >= atk[idx2])
      ans2 += (vv[i] - atk[idx2]), vis[i] = 1, idx2++;
  }
  if (idx2 != bb) return;
  for (long long int i = 0; i < aa; i++) {
    if (!vis[i]) ans2 += vv[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    string str;
    long long int xx;
    cin >> str >> xx;
    if (str == "ATK")
      atk.push_back(xx);
    else
      def.push_back(xx);
  }
  for (long long int i = 0; i < m; i++) {
    long long int yy;
    cin >> yy;
    vv.push_back(yy);
  }
  sort(vv.rbegin(), vv.rend());
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  doit1();
  doit2();
  cout << max(ans1, ans2);
  return 0;
}
