#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e15;
long long dp[101][101];
long long case1(vector<int> ATK, vector<int> DEF, vector<int> Z) {
  int i;
  multiset<int> C(Z.begin(), Z.end());
  for (i = 0; i < ATK.size(); ++i) {
    if (C.lower_bound(ATK[i]) != C.end())
      C.erase(C.lower_bound(ATK[i]));
    else
      return -INF;
  }
  for (i = 0; i < DEF.size(); ++i) {
    if (C.upper_bound(DEF[i]) != C.end())
      C.erase(C.upper_bound(DEF[i]));
    else
      return -INF;
  }
  C.clear();
  for (auto v : Z) C.insert(v);
  for (i = 0; i < DEF.size(); ++i) {
    if (C.upper_bound(DEF[i]) != C.end())
      C.erase(C.upper_bound(DEF[i]));
    else
      return -INF;
  }
  long long ans = 0;
  for (auto v : C) ans += v;
  for (auto v : ATK) ans -= v;
  return ans;
}
long long case2(vector<int> ATK, vector<int> DEF, vector<int> Z) {
  sort(Z.begin(), Z.end());
  sort(ATK.begin(), ATK.end());
  int i, j;
  for (i = 1; i <= ATK.size(); ++i)
    for (j = 1; j <= Z.size(); ++j) {
      dp[i][j] = -INF;
      if (Z[j - 1] >= ATK[i - 1])
        dp[i][j] = dp[i - 1][j - 1] + Z[j - 1] - ATK[i - 1];
      dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
    }
  return dp[ATK.size()][Z.size()];
}
int main() {
  int N, M, i, temp;
  cin >> N >> M;
  vector<int> ATK;
  vector<int> DEF;
  vector<int> A(M);
  string S;
  for (i = 0; i < N; ++i) {
    cin >> S >> temp;
    if (S[0] == 'A')
      ATK.push_back(temp);
    else
      DEF.push_back(temp);
  }
  for (i = 0; i < M; ++i) cin >> A[i];
  cout << max(case1(ATK, DEF, A), case2(ATK, DEF, A));
  return 0;
}
