#include <bits/stdc++.h>
using namespace std;
int at[110], de[110], at1, de1, sum[110];
int num[110], sum1[110], num1[110];
int main() {
  int n, m, re, ans;
  char s[10];
  while (~scanf("%d%d", &n, &m)) {
    at1 = 1;
    for (int i = 0; i < n; i++) {
      scanf("%s%d", s, &re);
      if (s[0] == 'A') {
        at[at1++] = re;
      } else {
        de[de1++] = re;
      }
    }
    sort(at + 1, at + at1);
    sum[1] = at[1];
    for (int i = 2; i < at1; i++) {
      sum[i] = sum[i - 1] + at[i];
    }
    sort(de, de + de1);
    for (int i = 0; i < m; i++) {
      scanf("%d", &num[i]);
    }
    sort(num, num + m);
    sum1[1] = num[m - 1];
    for (int i = m - 2, j = 2; i >= 0; i--, j++) {
      sum1[j] = sum1[j - 1] + num[i];
    }
    ans = sum1[1] - sum[1];
    for (int i = 2; i < min(at1, m + 1); i++) {
      if (sum1[i] - sum[i] <= ans) {
        break;
      }
      ans = sum1[i] - sum[i];
    }
    if (!de1) {
      if (at1 - 1 < m) {
        int flag = 0;
        int i, j;
        for (i = 1, j = 0; i < at1; i++, j++) {
          while (j < m && num[j] < at[i]) {
            j++;
          }
          if (j == m) {
            break;
          }
        }
        if (i == at1) {
          if (sum1[m] - sum[at1 - 1] > ans) {
            ans = sum1[m] - sum[at1 - 1];
          }
        }
      }
      printf("%d\n", max(0, ans));
    } else {
      if (n >= m) {
        printf("%d\n", max(0, ans));
      } else {
        int i, j, k;
        for (j = 0, k = 0, i = 0; i < de1 && j < m; i++, j++) {
          while (j < m && num[j] <= de[i]) {
            num1[k] = num[j];
            k++;
            j++;
          }
          if (j == m) {
            break;
          }
        }
        for (; j < m; j++, k++) {
          num1[k] = num[j];
        }
        if (i == de1) {
          memset(sum1, 0, sizeof(sum1));
          sum1[1] = num1[k - 1];
          for (i = k - 2, j = 2; i >= 0; i--, j++) {
            sum1[j] = sum1[j - 1] + num1[i];
          }
          int ans1 = sum1[1] - sum[1];
          for (i = 2; i < min(at1, k + 1); i++) {
            if (sum1[i] - sum[i] <= ans1) {
              break;
            }
            ans1 = sum1[i] - sum[i];
          }
          if (at1 - 1 < k) {
            int flag = 0;
            for (i = 1, j = 0; i < at1; i++, j++) {
              while (j < k && num1[j] < at[i]) {
                j++;
              }
              if (j == k) {
                break;
              }
            }
            if (i == at1) {
              if (sum1[k] - sum[at1 - 1] > ans1) {
                ans1 = sum1[k] - sum[at1 - 1];
              }
            }
          }
          if (ans < ans1) {
            ans = ans1;
          }
          printf("%d\n", max(0, ans));
        } else {
          printf("%d\n", max(0, ans));
        }
      }
    }
  }
  return 0;
}
