#include <bits/stdc++.h>
using namespace std;
int n, m, n1, n2;
int atk[105], def[105], c[105];
int dp[105][105];
int f(int a, int b) {
  if (a > n1 || b > m) return 0;
  if (dp[a][b] != -1) return dp[a][b];
  int ret = 0;
  if (c[b] >= atk[a]) ret = c[b] - atk[a] + f(a + 1, b + 1);
  return dp[a][b] = max(ret, f(a, b + 1));
}
int used[105];
int main() {
  char s[5];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int in;
    cin >> s >> in;
    if (*s == 'A')
      atk[++n1] = in;
    else
      def[++n2] = in;
  }
  for (int i = 1; i <= m; i++) cin >> c[i];
  sort(atk + 1, atk + 1 + n1);
  sort(c + 1, c + 1 + m);
  memset(dp, -1, sizeof(dp));
  int res1 = f(1, 1);
  bool flag = true;
  for (int i = 1; i <= n2; i++) {
    int mini = 0;
    for (int j = 1; j <= m; j++) {
      if (!used[j] && c[j] > def[i]) {
        mini = j;
        break;
      }
    }
    if (mini == 0) {
      flag = false;
      break;
    }
    used[mini] = 1;
  }
  if (!flag) {
    cout << res1 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = 1; i <= n1; i++) {
    int mini = 0;
    for (int j = 1; j <= m; j++) {
      if (!used[j] && c[j] >= atk[i]) {
        mini = j;
        break;
      }
    }
    if (mini == 0) {
      flag = false;
      break;
    }
    used[mini] = 1;
    sum += c[mini] - atk[i];
  }
  if (!flag) {
    cout << res1 << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++)
    if (!used[i]) sum += c[i];
  cout << max(res1, sum) << endl;
  return 0;
}
