#include <bits/stdc++.h>
using namespace std;
long double pi = 3.14159265358;
long long powr(long long a, long long b) {
  long long c = 1;
  long long i;
  for (i = 0; i < b; i++) c *= a;
  return c;
}
long long hell = 1000000007;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i;
  cin >> n >> m;
  vector<long long> attack;
  vector<long long> defense;
  vector<long long> b;
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long j;
    cin >> j;
    if (s == "ATK")
      attack.push_back(j);
    else
      defense.push_back(j);
  }
  for (i = 0; i < m; i++) {
    long long j;
    cin >> j;
    b.push_back(j);
  }
  sort((attack).begin(), (attack).end());
  sort((b).begin(), (b).end());
  reverse((b).begin(), (b).end());
  long long ans = 0;
  long long j = 0;
  i = 0;
  while (i < m && j < attack.size()) {
    if (b[i] >= attack[j]) {
      ans += (b[i] - attack[j]);
      i++;
      j++;
    } else
      break;
  }
  long long fans = ans;
  reverse((b).begin(), (b).end());
  ans = 0;
  bool p = true;
  if (m >= n) {
    multiset<long long> s;
    for (i = 0; i < m; i++) {
      s.insert(b[i]);
    }
    for (i = 0; i < defense.size(); i++) {
      multiset<long long>::iterator it;
      it = (s.upper_bound(defense[i]));
      if (it != s.end())
        s.erase(it);
      else {
        p = false;
        break;
      }
    }
    if (!p) {
      cout << fans;
      return 0;
    }
    for (i = 0; i < attack.size(); i++) {
      multiset<long long>::iterator it;
      it = (s.lower_bound(attack[i]));
      if (it != s.end()) {
        ans += *it - attack[i];
        s.erase(it);
      } else {
        p = false;
        break;
      }
    }
    if (!p) {
      cout << fans;
      return 0;
    }
    multiset<long long>::iterator it;
    for (it = s.begin(); it != s.end(); it++) ans += *it;
  }
  cout << max(ans, fans);
  return 0;
}
