#include <bits/stdc++.h>
using namespace std;
multiset<long long> a, d;
vector<long long> foo;
vector<long long> atk, def, mine;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, x, t, m, y, z, k;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    cin >> x;
    if (!s.compare("ATK")) {
      a.insert(x);
      atk.push_back(x);
    } else {
      d.insert(x);
      def.push_back(x);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    mine.push_back(x);
    foo.push_back(x);
  }
  sort(foo.begin(), foo.end(), greater<long long>());
  z = 0;
  for (int i = 0; i < m; i++) {
    bool ok = false;
    if (!a.size()) ok = true;
    if (!ok) {
      auto it = a.begin();
      ok = (foo[i] < *it);
    }
    if (!ok) {
      auto it = a.begin();
      z += (foo[i] - *it);
      a.erase(it);
    } else {
      if (!d.size()) {
        if (!a.size()) z += foo[i];
        continue;
      }
      auto bt = d.lower_bound(foo[i]);
      if (bt == d.begin()) continue;
      bt = prev(bt);
      d.erase(bt);
    }
  }
  long long res = 0;
  sort(mine.begin(), mine.end());
  sort(def.begin(), def.end());
  sort(atk.begin(), atk.end());
  int j = 0;
  bool found = true;
  for (int i = 0; i < def.size(); i++) {
    if (j == m) {
      found = false;
      break;
    }
    while (mine[j] <= def[i]) {
      j++;
      if (j == m) break;
    }
    if (j == m) {
      found = false;
      break;
    }
    mine[j] = 0;
    j++;
  }
  if (found) {
    sort(mine.begin(), mine.end());
    multiset<long long> boo;
    for (int i = 0; i < atk.size(); i++) {
      boo.insert(atk[i]);
    }
    for (int i = 0; i < m; i++) {
      if (!boo.size()) {
        res += mine[i];
        mine[i] = 0;
      } else {
        auto it = boo.upper_bound(mine[i]);
        if (it == boo.begin()) continue;
        it = prev(it);
        res += (mine[i] - *it);
        mine[i] = 0;
        boo.erase(it);
      }
    }
    if (!boo.size()) {
      for (int i = 0; i < m; i++) {
        res += mine[i];
      }
    }
    z = max(z, res);
  }
  cout << z;
  return 0;
}
