#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e2 + 5;
multiset<long long> s;
long long N, M;
long long a[maxN];
long long b[maxN];
long long atk[maxN];
long long def[maxN];
long long cnt1 = 0, cnt2 = 0;
bool flag = true;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (long long i = 1; i <= N; ++i) {
    string s;
    cin >> s;
    cin >> a[i];
    if (s == "ATK")
      atk[++cnt1] = a[i];
    else
      def[++cnt2] = a[i];
  }
  for (long long i = 1; i <= M; ++i) cin >> b[i];
  sort(atk + 1, atk + cnt1 + 1);
  sort(def + 1, def + cnt2 + 1);
  sort(a + 1, a + N + 1, greater<long long>());
  sort(b + 1, b + M + 1, greater<long long>());
  for (long long i = 1; i <= N; ++i) {
    if (b[i] < a[i] || M < N) {
      flag = false;
      break;
    }
  }
  long long res = 0;
  if (flag) {
    for (long long i = 1; i <= M; ++i) s.insert(b[i]);
    for (long long i = 1; i <= cnt2; ++i) {
      long long x = *s.upper_bound(def[i]);
      s.erase(s.find(x));
    }
    long long tot = 0;
    for (long long i = 1; i <= cnt1; ++i) tot += atk[i];
    while (!s.empty()) {
      res += *s.begin();
      s.erase(s.find(*s.begin()));
    }
    res -= tot;
  }
  long long res2 = 0;
  for (long long i = 1; i <= cnt1; ++i) {
    if (atk[i] > b[i]) break;
    res2 += b[i] - atk[i];
  }
  cout << max(res, res2) << '\n';
  return 0;
}
