#include <bits/stdc++.h>
using namespace std;
int n, m, dp[102][102][102][2], a[102];
vector<int> atk, def;
int solve(int i, int j, int k, int x) {
  if (i == m) {
    if (x && (j < atk.size() || k < def.size())) return -INT_MAX;
    return 0;
  }
  if (dp[i][j][k][x] != -1) return dp[i][j][k][x];
  int c = max(solve(i + 1, j, k, 1) + a[i], solve(i + 1, j, k, x));
  if (j < atk.size() && a[i] >= atk[j])
    c = max(c, solve(i + 1, j + 1, k, x) + a[i] - atk[j]);
  if (k < def.size() && a[i] > def[k]) c = max(c, solve(i + 1, j, k + 1, x));
  return dp[i][j][k][x] = c;
}
int main() {
  memset(dp, -1, sizeof dp);
  string s;
  int x;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> s >> x, (s == "ATK" ? atk.push_back(x) : def.push_back(x));
  for (int i = 0; i < m; i++) cin >> a[i];
  sort(def.begin(), def.end());
  sort(atk.begin(), atk.end());
  sort(a, a + m);
  cout << solve(0, 0, 0, 0);
  return 0;
}
