#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const long long LINF = 2e18;
int m, n, ans, sum, lft, cnt[N];
bool u[N];
vector<int> atk, def, x;
multiset<int> st;
int main() {
  if ("" != "") {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  bool ok = 1;
  cin >> m >> n;
  for (int i = 1; i <= m; ++i) {
    string s;
    int val;
    cin >> s >> val;
    if (s[0] == 'A') {
      atk.push_back(val);
    } else {
      def.push_back(val);
    }
  }
  atk.push_back(0);
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  for (int i = 1; i <= n; ++i) {
    int val;
    cin >> val;
    x.push_back(val);
    st.insert(val);
  }
  sort(x.begin(), x.end());
  x.push_back(0);
  reverse(x.begin(), x.end());
  for (int i = 0; i < def.size(); ++i) {
    auto it = st.upper_bound(def[i]);
    if (it == st.end()) {
      ok = 0;
      break;
    }
    cnt[*it]++;
    st.erase(it);
  }
  int pos = atk.size();
  pos--;
  for (int i = 1; i < x.size(); ++i) {
    if (ok == 0) break;
    if (cnt[x[i]]) {
      cnt[x[i]]--;
      continue;
    }
    if (pos < 0 || x[i] < atk[pos]) {
      break;
    }
    ans += x[i] - atk[pos];
    if (pos) pos--;
  }
  for (int i = 1; i < min(atk.size(), x.size()); ++i) {
    if (atk[i] > x[i]) break;
    sum += x[i] - atk[i];
  }
  cout << max(ans, sum);
  return 0;
}
