#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void maz(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void miz(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
const int N = 100100;
int n, m;
int A[N];
vector<int> atk, def;
bool ok(int A[], int n) {
  for (int i = 0; i < n; i++)
    if (A[i] < atk[i]) return false;
  return true;
}
int sum(int A[], int n) {
  int ans = 0;
  for (int i = 0; i < n; i++) ans += A[i];
  return ans;
}
int solve1() {
  int ans = 0;
  int n = min((int)atk.size(), m);
  int now = 0;
  for (int len = 1; len <= n; len++) {
    now += atk[len - 1];
    if (ok(A + m - len, len)) maz(ans, sum(A + m - len, len) - now);
  }
  return ans;
}
int solve2() {
  for (auto c : def) {
    bool flag = false;
    for (int i = 0; i < m; i++)
      if (A[i] > c) {
        swap(A[i], A[m - 1]);
        m--;
        sort(A, A + m);
        flag = true;
        break;
      }
    if (!flag) return 0;
  }
  if (m < atk.size()) return 0;
  if (!ok(A + m - atk.size(), atk.size())) return 0;
  int ans = 0;
  for (auto c : atk) ans += c;
  return sum(A, m) - ans;
}
int main() {
  int T = 1;
  for (int t = 0; t < T; t++) {
    scanf("%d", &n);
    scanf("%d", &m);
    atk.clear();
    def.clear();
    for (int i = 0; i < n; i++) {
      char s[5];
      int v;
      scanf("%s%d", s, &v);
      if (s[0] == 'A')
        atk.push_back(v);
      else
        def.push_back(v);
    }
    for (int i = 0; i < m; i++) scanf("%d", &A[i]);
    sort(A, A + m);
    sort((atk).begin(), (atk).end());
    sort((def).begin(), (def).end());
    int ans1 = solve1(), ans2 = solve2();
    printf("%d\n", max(ans1, ans2));
  }
}
