#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  pair<int, int> arr[n];
  for (int(i) = (0); (i) < (n); ++i) {
    string s;
    int pow;
    cin >> s >> pow;
    if (s == "ATK")
      arr[i] = make_pair(0, pow);
    else
      arr[i] = make_pair(1, pow);
  }
  sort(arr, arr + n);
  int mass[m];
  for (int(i) = (0); (i) < (m); ++i) cin >> mass[i];
  sort(mass, mass + m);
  reverse(mass, mass + m);
  int ans = 0, cur = 0;
  for (int(i) = (0); (i) < (min(n, m)); ++i)
    if (!arr[i].first && mass[i] >= arr[i].second)
      cur += mass[i] - arr[i].second;
  ans = max(ans, cur);
  vector<int> s;
  for (int(i) = (0); (i) < (m); ++i) s.push_back(mass[m - i - 1]);
  bool flag = true;
  for (int(i) = (n)-1; (i) >= (0); --i) {
    if (!arr[i].first) break;
    if (upper_bound((s).begin(), (s).end(), arr[i].second) == s.end()) {
      flag = false;
      break;
    }
    s.erase(upper_bound((s).begin(), (s).end(), arr[i].second));
  }
  if (flag) {
    cur = 0;
    for (auto el : s) cur += el;
    vector<int> tmp;
    for (int(i) = (0); (i) < (n); ++i)
      if (!arr[i].first) {
        cur -= arr[i].second;
        tmp.push_back(arr[i].second);
      }
    reverse((s).begin(), (s).end());
    reverse((tmp).begin(), (tmp).end());
    if (((int)(s).size()) >= ((int)(tmp).size())) {
      for (int(i) = (0); (i) < (((int)(tmp).size())); ++i)
        if (s[i] < tmp[i]) flag = false;
    } else
      flag = false;
    if (flag) ans = max(ans, cur);
  }
  cout << ans;
  return 0;
}
