#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) {
  a.first += b.first;
  a.second += b.second;
  return a;
}
pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) {
  a.first -= b.first;
  a.second -= b.second;
  return a;
}
template <class T, class U>
bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {
  return a.second < b.second;
}
template <class T>
T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    T t = b;
    b = a % b;
    a = t;
  }
  return a;
}
template <class T>
pair<T, T> ext_gcd(T a, T b) {
  T a0 = 1, a1 = 0, b0 = 0, b1 = 1;
  if (a < 0) {
    a = -a;
    a0 = -1;
  }
  if (b < 0) {
    b = -b;
    b1 = -1;
  }
  while (b) {
    T t, q = a / b;
    t = b;
    b = a - b * q;
    a = t;
    t = b0;
    b0 = a0 - b0 * q;
    a0 = t;
    t = b1;
    b1 = a1 - b1 * q;
    a1 = t;
  }
  return make_pair(a0, a1);
}
inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; }
int an, bn;
vector<int> aa, ad;
vector<int> ba;
inline int sub(int qa, int qd) {
  int ret = 0, j;
  vector<int> b = ba, tmp;
  tmp.reserve(bn);
  j = 0;
  for (int i = 0; i < qd; i++) {
    while (j < b.size() && b[j] <= ad[i]) tmp.push_back(b[j++]);
    if (j >= b.size()) return 0;
    j++;
  }
  while (j < b.size()) tmp.push_back(b[j++]);
  b = tmp;
  tmp.clear();
  if (b.size() < qa) return 0;
  j = b.size() - qa;
  for (int t = 0; t < j; t++) tmp.push_back(b[t]);
  for (int i = 0; i < qa; i++) {
    while (j < b.size() && b[j] < aa[i]) tmp.push_back(b[j++]);
    if (j >= b.size()) return 0;
    ret += b[j] - aa[i];
    j++;
  }
  while (j < b.size()) tmp.push_back(b[j++]);
  b = tmp;
  if (qa >= aa.size() && qd >= ad.size()) {
    for (int i = 0; i < b.size(); i++) ret += b[i];
  }
  return ret;
}
int solve() {
  sort(ba.begin(), ba.end());
  sort(ad.begin(), ad.end());
  sort(aa.begin(), aa.end());
  int sol = 0;
  for (int qa = 0; qa <= aa.size(); qa++) {
    for (int qdz = 0; qdz < 2; qdz++) {
      int qd;
      if (qdz)
        qd = ad.size();
      else
        qd = 0;
      sol = max(sol, sub(qa, qd));
    }
  }
  return sol;
}
int main(void) {
  char in[30];
  scanf("%d %d", &(an), &(bn));
  for (int i = 0; i < an; i++) {
    int val;
    scanf("%s", in);
    scanf("%d", &(val));
    if (in[0] == 'D')
      ad.push_back(val);
    else
      aa.push_back(val);
  }
  for (int i = 0; i < bn; i++) {
    int val;
    scanf("%d", &(val));
    ba.push_back(val);
  }
  printf("%d\n", solve());
  return 0;
}
