#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
inline long long read() {
  bool f = 0;
  long long x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return x;
}
inline void scf(int &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
void scf(int &x, int &y) {
  scf(x);
  return scf(y);
}
void scf(int &x, int &y, int &z) {
  scf(x);
  scf(y);
  return scf(z);
}
int n, m, ans;
vector<int> atk, def, card;
inline bool check(const vector<int> &atk, const vector<int> &card) {
  for (int i = 0; i < ((int)atk.size()); i++)
    if (atk[i] > card[i]) return 0;
  return 1;
}
int main() {
  scf(n, m);
  for (int i = (1); i <= (n); i++) {
    char c = getchar();
    while (c != 'A' && c != 'D') c = getchar();
    int x;
    scf(x);
    if (c == 'A')
      atk.push_back(x);
    else
      def.push_back(x);
  }
  for (int i = (1); i <= (m); i++) {
    int x;
    scf(x);
    card.push_back(x);
  }
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  sort(card.begin(), card.end());
  vector<int> ta, tc;
  ta.clear();
  for (int i = 0; i < ((int)atk.size()); i++) {
    if (i >= (int)card.size()) break;
    ta.push_back(atk[i]);
    tc.clear();
    tc.insert(tc.begin(), card.end() - i - 1, card.end());
    if (check(ta, tc)) {
      int calc = 0;
      for (int j = (0); j <= (i); j++) calc += tc[j] - ta[j];
      if (calc > ans) ans = calc;
    }
  }
  if (n > m) {
    printf("%d\n", ans);
    return 0;
  }
  for (auto x : def) {
    bool f = 1;
    for (auto y = card.begin(); y != card.end(); y++)
      if (*y > x) {
        f = 0;
        card.erase(y);
        break;
      }
    if (f) {
      printf("%d\n", ans);
      return 0;
    }
  }
  tc.clear();
  tc.insert(tc.begin(), card.end() - (int)atk.size(), card.end());
  if (check(atk, tc)) {
    int calc = 0;
    for (auto x : atk) calc -= x;
    for (auto x : card) calc += x;
    if (calc > ans) ans = calc;
  }
  printf("%d\n", ans);
  return 0;
}
