#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int y[m];
  vector<int> attacks, defense;
  for (int i = 0; i < n; i++) {
    string type;
    int k;
    cin >> type >> k;
    if (type == "ATK")
      attacks.push_back(k);
    else
      defense.push_back(k);
  }
  sort(attacks.begin(), attacks.end());
  sort(defense.begin(), defense.end());
  multiset<int> s;
  for (int i = 0; i < m; i++) cin >> y[i], s.insert(y[i]);
  sort(y, y + m, greater<int>());
  int res = 0;
  for (int take = 1; take <= min(m, (int)attacks.size()); take++) {
    int index = take - 1, k = 0, fail = 0;
    int ans = 0;
    while (index >= 0) {
      if (y[k] >= attacks[index]) {
        ans += y[k] - attacks[index];
      } else {
        fail = 1;
        break;
      }
      k++;
      index--;
    }
    if (fail) break;
    res = max(res, ans);
  }
  int fail = 0;
  for (auto x : defense) {
    auto it = s.upper_bound(x);
    if (it == s.end()) {
      fail = 1;
      break;
    }
    s.erase(it);
  }
  int ans = 0;
  for (auto x : attacks) {
    auto it = s.lower_bound(x);
    if (it == s.end()) {
      fail = 1;
      break;
    }
    s.erase(it);
    ans += (*it) - x;
  }
  for (auto x : s) {
    ans += x;
  }
  if (!fail) res = max(res, ans);
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
