#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
multiset<int> atk, def;
vector<int> a;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, k, m, n;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    string t;
    cin >> t >> k;
    if (t == "ATK")
      atk.insert(k);
    else
      def.insert(k);
  }
  for (int i = 1; i <= m; ++i) {
    cin >> k;
    a.push_back(k);
  }
  sort(a.begin(), a.end());
  long long ans = 0;
  vector<int> vatk(atk.begin(), atk.end());
  sort(vatk.begin(), vatk.end());
  for (int i = 1; i <= min(vatk.size(), a.size()); ++i) {
    long long tans = 0, mode = 1;
    for (int j = 0; j < i; ++j)
      if (vatk[j] > a[a.size() - 1 - j]) {
        mode = 0;
        break;
      }
    if (mode == 0) continue;
    for (int j = 0; j < i; ++j) tans += a[a.size() - 1 - j] - vatk[j];
    ans = max(ans, tans);
  }
  long long tans = 0, mode = 1;
  multiset<int> st(a.begin(), a.end());
  for (auto it : def) {
    auto pt = st.upper_bound(it);
    if (pt == st.end()) {
      mode = 0;
      break;
    }
    st.erase(pt);
  }
  for (auto it : atk) {
    auto pt = st.lower_bound(it);
    if (pt == st.end()) {
      mode = 0;
      break;
    }
    tans += *pt - it;
    st.erase(pt);
  }
  for (auto it : st) tans += it;
  if (mode) ans = max(ans, tans);
  cout << ans << endl;
  return 0;
}
