#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 100;
int n, m, ans, a[maxn], k;
vector<int> atk, def;
multiset<int> A;
void sol1() {
  vector<int>::iterator it;
  multiset<int>::iterator it1;
  ans = 0;
  for (it = def.begin(); it != def.end(); it++) {
    it1 = A.upper_bound(*it);
    if (it1 == A.end())
      return;
    else
      A.erase(it1);
  }
  for (it = atk.end() - 1; it != atk.begin() - 1; it--) {
    it1 = A.lower_bound(*it);
    if (it1 == A.end())
      return;
    else
      A.erase(it1);
    ans += *it1 - *it;
  }
  for (it1 = A.begin(); it1 != A.end(); it1++) ans += *it1;
}
void sol2() {
  for (int tot = 0; tot < atk.size(); tot++) {
    if (m <= tot) break;
    int now = 0;
    for (int i = 0; i <= tot; i++) {
      if (a[m - tot - 1 + i] >= atk[i]) now += a[m - tot - 1 + i] - atk[i];
    }
    ans = max(ans, now);
  }
}
int main() {
  cin >> n >> m;
  string s;
  for (int i = 0, x; i < n; i++) {
    cin >> s >> x;
    if (s[0] == 'A')
      atk.push_back(x);
    else
      def.push_back(x);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    A.insert(a[i]);
  }
  sort(a, a + m);
  sol1();
  sol2();
  cout << ans << endl;
}
