#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200];
int b[200];
int c[200];
int lena;
int lenb;
int vis[2000];
int cmp(int aa, int bb) { return aa > bb; }
int main() {
  cin >> n >> m;
  char s[20];
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (!strcmp(s, "ATK")) {
      cin >> a[++lena];
    } else {
      cin >> b[++lenb];
    }
  }
  for (int i = 1; i <= m; i++) cin >> c[i];
  int ans1 = 0;
  sort(a + 1, a + 1 + lena);
  sort(b + 1, b + 1 + lenb);
  sort(c + 1, c + 1 + m, cmp);
  for (int i = 1; i <= lena; i++) {
    if (c[i] < a[i]) {
      break;
    }
    ans1 += c[i] - a[i];
  }
  memset(vis, 0, sizeof(vis));
  int ans2 = 0;
  for (int i = 1; i <= lenb; i++) {
    int minn = 1e9;
    int pos = 0;
    for (int j = 1; j <= m; j++) {
      if (c[j] > b[i] && !vis[j]) {
        if (c[j] - b[i] < minn) {
          pos = j;
          minn = c[j] - b[i];
        }
      }
    }
    if (!pos) {
      cout << ans1 << endl;
      return 0;
    }
    vis[pos] = 1;
  }
  for (int i = 1; i <= lena; i++) {
    int minn = 1e9;
    int pos = 0;
    for (int j = 1; j <= m; j++) {
      if (c[j] >= a[i] && !vis[j]) {
        if (c[j] - a[i] < minn) {
          pos = j;
          minn = c[j] - a[i];
        }
      }
    }
    if (!pos) {
      cout << max(ans1, ans2) << endl;
      return 0;
    }
    vis[pos] = 1;
    ans2 += minn;
  }
  for (int i = 1; i <= m; i++) {
    if (!vis[i]) {
      ans2 += c[i];
    }
  }
  cout << max(ans2, ans1) << endl;
  return 0;
}
