#include <bits/stdc++.h>
using namespace std;
int a[110];
int atk[8010];
int def[8010];
bool used[110];
int atk2[8010];
int def2[8010];
int main() {
  int n, m;
  char str[20];
  int p;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(atk, 0, sizeof(atk));
    memset(def, 0, sizeof(def));
    memset(atk2, 0, sizeof(atk2));
    memset(def2, 0, sizeof(def2));
    memset(used, false, sizeof(used));
    for (int i = 0; i < n; i++) {
      scanf("%s%d", str, &p);
      if (str[0] == 'A') {
        atk[p]++;
        atk2[p]++;
      } else {
        def[p]++;
        def2[p]++;
      }
    }
    for (int i = 0; i < m; i++) scanf("%d", &a[i]);
    sort(a, a + m);
    int ans = 0;
    int temp = m - 1;
    int cnt = 0;
    for (int i = 0; i < m; i++) {
      if (used[i]) continue;
      bool flag = false;
      for (int j = 0; j <= a[i]; j++)
        if (atk[j] > 0) {
          atk[j]--;
          flag = true;
          ans += a[temp] - j;
          used[temp] = true;
          temp--;
          cnt++;
          i--;
          break;
        }
      if (flag) continue;
      for (int j = 0; j < a[i]; j++)
        if (def[j] > 0) {
          def[j]--;
          flag = true;
          cnt++;
          used[i] = true;
          break;
        }
      if (flag) continue;
    }
    if (cnt == n) {
      for (int j = 0; j < m; j++)
        if (!used[j]) ans += a[j];
    }
    memset(used, false, sizeof(used));
    for (int i = 0; i <= 8000; i++) {
      atk[i] = atk2[i];
      def[i] = def2[i];
    }
    int ans2 = 0;
    cnt = 0;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < a[i]; j++)
        if (def[j] > 0) {
          def[j]--;
          cnt++;
          used[i] = true;
          break;
        }
    }
    for (int i = 0; i < m; i++) {
      if (used[i]) continue;
      for (int j = 0; j <= a[i]; j++)
        if (atk[j] > 0) {
          atk[j]--;
          ans2 += a[i] - j;
          used[i] = true;
          cnt++;
          break;
        }
    }
    if (cnt == n) {
      for (int j = 0; j < m; j++)
        if (!used[j]) ans2 += a[j];
    }
    printf("%d\n", max(ans, ans2));
  }
  return 0;
}
