#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<long long> atk, def;
  for (long long i = 0; i < n; i++) {
    string s;
    long long x;
    cin >> s >> x;
    if (s == "ATK")
      atk.push_back(x);
    else
      def.push_back(x);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  vector<long long> v(m);
  for (long long i = 0; i < m; i++) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 0;
  long long ind = m - 1;
  for (long long i = 0; i < atk.size(); i++) {
    if (ind == -1) break;
    if (v[ind] < atk[i]) break;
    ans += v[ind] - atk[i];
    ind--;
  }
  if (m < n) {
    cout << ans;
    return 0;
  }
  ind = 0;
  vector<long long> tmp;
  for (long long i = 0; i < def.size(); i++) {
    while (ind < m && def[i] >= v[ind]) tmp.push_back(v[ind++]);
    if (ind == m) {
      cout << ans;
      return 0;
    }
    ind++;
  }
  for (long long i = ind; i < v.size(); i++) tmp.push_back(v[i]);
  long long val = 0;
  ind = 0;
  for (long long i = 0; i < atk.size(); i++) {
    while (ind < tmp.size() && tmp[ind] < atk[i]) {
      val += tmp[ind];
      ind++;
    }
    if (ind == tmp.size()) {
      cout << ans << '\n';
      return 0;
    }
    val += tmp[ind] - atk[i];
    ind++;
  }
  for (long long i = ind; i < tmp.size(); i++) val += tmp[i];
  cout << max(ans, val);
}
