#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int a[111], b[111], c[111];
int tmp[111];
int main() {
  int n, m;
  cin >> n >> m;
  char s[10];
  int ca = 0, cb = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    if (s[0] == 'A') {
      scanf("%d", a + ca);
      ca++;
    } else {
      scanf("%d", b + cb);
      cb++;
    }
  }
  sort(a, a + ca);
  sort(b, b + cb);
  for (int i = 0; i < m; i++) scanf("%d", c + i);
  sort(c, c + m);
  int ans1 = 0, sum = 0, ans2 = 0;
  for (int k = 1; k <= min(ca, m); k++) {
    int fl = 1;
    for (int i = 0; i < k; i++) {
      if (a[i] > c[m - k + i]) {
        fl = 0;
        break;
      }
    }
    if (fl)
      sum += c[m - k] - a[k - 1], ans1 = max(ans1, sum);
    else
      break;
  }
  int mm = 0, cur = 0;
  for (int i = 0; i < m; i++) {
    if (cur < cb && b[cur] < c[i])
      cur++;
    else
      tmp[mm++] = c[i], ans2 += c[i];
  }
  if (cur == cb && mm >= ca) {
    int fl = 1;
    for (int i = 0; i < ca; i++) {
      if (a[i] > tmp[mm - ca + i]) {
        fl = 0;
        break;
      }
      ans2 -= a[i];
    }
    if (!fl) ans2 = 0;
  } else
    ans2 = 0;
  cout << max(ans1, ans2) << endl;
  return 0;
}
