#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const long long maxn = 1e5 + 10;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e10 + 100;
pair<long long, long long> a[maxn];
bool mark[maxn];
long long b[maxn];
long long res;
int32_t main() {
  long long n = in(), m = in();
  for (long long i = 0; i < n; i++) {
    string x = get();
    a[i] = {in(), x[0] != 'A'};
  }
  sort(a, a + n,
       [](const pair<long long, long long> &A,
          const pair<long long, long long> &B) {
         return B.second != A.second ? A.second < B.second : A.first > B.first;
       });
  for (long long i = 0; i < m; i++) b[i] = in();
  sort(b, b + m, greater<long long>());
  long long lst = -1;
  for (long long i = 0; i < n; i++) {
    if (a[i].second == 0) {
      lst = i;
    }
  }
  if (lst + 1) {
    for (long long i = 0; i < n && lst >= 0 && b[i] >= a[lst].first; i++) {
      res += b[i] - a[lst--].first;
    }
  }
  long long cur = n - 1;
  for (long long i = m - 1; i >= 0 && cur >= 0 && a[cur].second; i--) {
    if (b[i] > a[cur].first) {
      mark[i] = true;
      cur--;
    }
  }
  if (cur == -1 || a[cur].second == 0) {
    cur = 0;
    long long res2 = 0;
    for (long long i = 0; i < m && cur < n && a[cur].second == 0; i++) {
      if (!mark[i] && b[i] >= a[cur].first) {
        res2 += b[i] - a[cur++].first;
        mark[i] = true;
      }
    }
    if (cur == n || a[cur].second == 1) {
      for (long long i = 0; i < m; i++) {
        if (!mark[i]) res2 += b[i];
      }
      res = max(res, res2);
    }
  }
  cout << res << "\n";
}
