#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 1e1;
const int ninf = -1e9;
int dp[N][N][N][2];
bool vis[N][N][N][2];
vector<int> mera, atk, def;
int solve(int i, int j, int k, int all) {
  if (i == mera.size() && all == 0) return 0;
  if (i == mera.size() && all == 1) {
    if (j == atk.size() && k == def.size()) return 0;
    return ninf;
  }
  if (vis[i][j][k][all]) return dp[i][j][k][all];
  vis[i][j][k][all] = 1;
  int ans = solve(i + 1, j, k, all);
  ans = max(ans, solve(i + 1, j, k, 1) + mera[i]);
  if (j < atk.size() && mera[i] >= atk[j])
    ans = max(ans, solve(i + 1, j + 1, k, all) + mera[i] - atk[j]);
  if (k < def.size() && mera[i] > def[k])
    ans = max(ans, solve(i + 1, j, k + 1, all));
  return dp[i][j][k][all] = ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  string s;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> s >> x;
    if (s == "ATK")
      atk.push_back(x);
    else
      def.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    mera.push_back(x);
  }
  sort(mera.begin(), mera.end());
  sort(atk.begin(), atk.end());
  sort(def.begin(), def.end());
  cout << solve(0, 0, 0, 0);
  return 0;
}
